home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / src / linux-headers-2.6.28-15 / include / linux / security.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-09  |  107.5 KB  |  2,912 lines

  1. /*
  2.  * Linux Security plug
  3.  *
  4.  * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com>
  5.  * Copyright (C) 2001 Greg Kroah-Hartman <greg@kroah.com>
  6.  * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
  7.  * Copyright (C) 2001 James Morris <jmorris@intercode.com.au>
  8.  * Copyright (C) 2001 Silicon Graphics, Inc. (Trust Technology Group)
  9.  *
  10.  *    This program is free software; you can redistribute it and/or modify
  11.  *    it under the terms of the GNU General Public License as published by
  12.  *    the Free Software Foundation; either version 2 of the License, or
  13.  *    (at your option) any later version.
  14.  *
  15.  *    Due to this file being licensed under the GPL there is controversy over
  16.  *    whether this permits you to write a module that #includes this file
  17.  *    without placing your module under the GPL.  Please consult a lawyer for
  18.  *    advice before doing this.
  19.  *
  20.  */
  21.  
  22. #ifndef __LINUX_SECURITY_H
  23. #define __LINUX_SECURITY_H
  24.  
  25. #include <linux/fs.h>
  26. #include <linux/binfmts.h>
  27. #include <linux/signal.h>
  28. #include <linux/resource.h>
  29. #include <linux/sem.h>
  30. #include <linux/shm.h>
  31. #include <linux/msg.h>
  32. #include <linux/sched.h>
  33. #include <linux/key.h>
  34. #include <linux/xfrm.h>
  35. #include <net/flow.h>
  36.  
  37. /* Maximum number of letters for an LSM name string */
  38. #define SECURITY_NAME_MAX    10
  39.  
  40. struct ctl_table;
  41. struct audit_krule;
  42.  
  43. /*
  44.  * These functions are in security/capability.c and are used
  45.  * as the default capabilities functions
  46.  */
  47. extern int cap_capable(struct task_struct *tsk, int cap);
  48. extern int cap_settime(struct timespec *ts, struct timezone *tz);
  49. extern int cap_ptrace_may_access(struct task_struct *child, unsigned int mode);
  50. extern int cap_ptrace_traceme(struct task_struct *parent);
  51. extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
  52. extern int cap_capset_check(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
  53. extern void cap_capset_set(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
  54. extern int cap_bprm_set_security(struct linux_binprm *bprm);
  55. extern void cap_bprm_apply_creds(struct linux_binprm *bprm, int unsafe);
  56. extern int cap_bprm_secureexec(struct linux_binprm *bprm);
  57. extern int cap_inode_setxattr(struct dentry *dentry, struct vfsmount *mnt,
  58.                   const char *name, const void *value, size_t size,
  59.                   int flags, struct file *file);
  60. extern int cap_inode_removexattr(struct dentry *dentry, struct vfsmount *mnt,
  61.                  const char *name, struct file *file);
  62. extern int cap_inode_need_killpriv(struct dentry *dentry);
  63. extern int cap_inode_killpriv(struct dentry *dentry);
  64. extern int cap_task_post_setuid(uid_t old_ruid, uid_t old_euid, uid_t old_suid, int flags);
  65. extern void cap_task_reparent_to_init(struct task_struct *p);
  66. extern int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
  67.               unsigned long arg4, unsigned long arg5, long *rc_p);
  68. extern int cap_task_setscheduler(struct task_struct *p, int policy, struct sched_param *lp);
  69. extern int cap_task_setioprio(struct task_struct *p, int ioprio);
  70. extern int cap_task_setnice(struct task_struct *p, int nice);
  71. extern int cap_syslog(int type);
  72. extern int cap_vm_enough_memory(struct mm_struct *mm, long pages);
  73.  
  74. struct msghdr;
  75. struct sk_buff;
  76. struct sock;
  77. struct sockaddr;
  78. struct socket;
  79. struct flowi;
  80. struct dst_entry;
  81. struct xfrm_selector;
  82. struct xfrm_policy;
  83. struct xfrm_state;
  84. struct xfrm_user_sec_ctx;
  85. struct seq_file;
  86.  
  87. extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
  88. extern int cap_netlink_recv(struct sk_buff *skb, int cap);
  89.  
  90. extern unsigned long mmap_min_addr;
  91. /*
  92.  * Values used in the task_security_ops calls
  93.  */
  94. /* setuid or setgid, id0 == uid or gid */
  95. #define LSM_SETID_ID    1
  96.  
  97. /* setreuid or setregid, id0 == real, id1 == eff */
  98. #define LSM_SETID_RE    2
  99.  
  100. /* setresuid or setresgid, id0 == real, id1 == eff, uid2 == saved */
  101. #define LSM_SETID_RES    4
  102.  
  103. /* setfsuid or setfsgid, id0 == fsuid or fsgid */
  104. #define LSM_SETID_FS    8
  105.  
  106. /* forward declares to avoid warnings */
  107. struct sched_param;
  108. struct request_sock;
  109.  
  110. /* bprm_apply_creds unsafe reasons */
  111. #define LSM_UNSAFE_SHARE    1
  112. #define LSM_UNSAFE_PTRACE    2
  113. #define LSM_UNSAFE_PTRACE_CAP    4
  114.  
  115. #ifdef CONFIG_SECURITY
  116.  
  117. struct security_mnt_opts {
  118.     char **mnt_opts;
  119.     int *mnt_opts_flags;
  120.     int num_mnt_opts;
  121. };
  122.  
  123. static inline void security_init_mnt_opts(struct security_mnt_opts *opts)
  124. {
  125.     opts->mnt_opts = NULL;
  126.     opts->mnt_opts_flags = NULL;
  127.     opts->num_mnt_opts = 0;
  128. }
  129.  
  130. static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  131. {
  132.     int i;
  133.     if (opts->mnt_opts)
  134.         for (i = 0; i < opts->num_mnt_opts; i++)
  135.             kfree(opts->mnt_opts[i]);
  136.     kfree(opts->mnt_opts);
  137.     opts->mnt_opts = NULL;
  138.     kfree(opts->mnt_opts_flags);
  139.     opts->mnt_opts_flags = NULL;
  140.     opts->num_mnt_opts = 0;
  141. }
  142.  
  143. /**
  144.  * struct security_operations - main security structure
  145.  *
  146.  * Security module identifier.
  147.  *
  148.  * @name:
  149.  *    A string that acts as a unique identifeir for the LSM with max number
  150.  *    of characters = SECURITY_NAME_MAX.
  151.  *
  152.  * Security hooks for program execution operations.
  153.  *
  154.  * @bprm_alloc_security:
  155.  *    Allocate and attach a security structure to the @bprm->security field.
  156.  *    The security field is initialized to NULL when the bprm structure is
  157.  *    allocated.
  158.  *    @bprm contains the linux_binprm structure to be modified.
  159.  *    Return 0 if operation was successful.
  160.  * @bprm_free_security:
  161.  *    @bprm contains the linux_binprm structure to be modified.
  162.  *    Deallocate and clear the @bprm->security field.
  163.  * @bprm_apply_creds:
  164.  *    Compute and set the security attributes of a process being transformed
  165.  *    by an execve operation based on the old attributes (current->security)
  166.  *    and the information saved in @bprm->security by the set_security hook.
  167.  *    Since this hook function (and its caller) are void, this hook can not
  168.  *    return an error.  However, it can leave the security attributes of the
  169.  *    process unchanged if an access failure occurs at this point.
  170.  *    bprm_apply_creds is called under task_lock.  @unsafe indicates various
  171.  *    reasons why it may be unsafe to change security state.
  172.  *    @bprm contains the linux_binprm structure.
  173.  * @bprm_post_apply_creds:
  174.  *    Runs after bprm_apply_creds with the task_lock dropped, so that
  175.  *    functions which cannot be called safely under the task_lock can
  176.  *    be used.  This hook is a good place to perform state changes on
  177.  *    the process such as closing open file descriptors to which access
  178.  *    is no longer granted if the attributes were changed.
  179.  *    Note that a security module might need to save state between
  180.  *    bprm_apply_creds and bprm_post_apply_creds to store the decision
  181.  *    on whether the process may proceed.
  182.  *    @bprm contains the linux_binprm structure.
  183.  * @bprm_set_security:
  184.  *    Save security information in the bprm->security field, typically based
  185.  *    on information about the bprm->file, for later use by the apply_creds
  186.  *    hook.  This hook may also optionally check permissions (e.g. for
  187.  *    transitions between security domains).
  188.  *    This hook may be called multiple times during a single execve, e.g. for
  189.  *    interpreters.  The hook can tell whether it has already been called by
  190.  *    checking to see if @bprm->security is non-NULL.  If so, then the hook
  191.  *    may decide either to retain the security information saved earlier or
  192.  *    to replace it.
  193.  *    @bprm contains the linux_binprm structure.
  194.  *    Return 0 if the hook is successful and permission is granted.
  195.  * @bprm_check_security:
  196.  *    This hook mediates the point when a search for a binary handler    will
  197.  *    begin.  It allows a check the @bprm->security value which is set in
  198.  *    the preceding set_security call.  The primary difference from
  199.  *    set_security is that the argv list and envp list are reliably
  200.  *    available in @bprm.  This hook may be called multiple times
  201.  *    during a single execve; and in each pass set_security is called
  202.  *    first.
  203.  *    @bprm contains the linux_binprm structure.
  204.  *    Return 0 if the hook is successful and permission is granted.
  205.  * @bprm_secureexec:
  206.  *    Return a boolean value (0 or 1) indicating whether a "secure exec"
  207.  *    is required.  The flag is passed in the auxiliary table
  208.  *    on the initial stack to the ELF interpreter to indicate whether libc
  209.  *    should enable secure mode.
  210.  *    @bprm contains the linux_binprm structure.
  211.  *
  212.  * Security hooks for filesystem operations.
  213.  *
  214.  * @sb_alloc_security:
  215.  *    Allocate and attach a security structure to the sb->s_security field.
  216.  *    The s_security field is initialized to NULL when the structure is
  217.  *    allocated.
  218.  *    @sb contains the super_block structure to be modified.
  219.  *    Return 0 if operation was successful.
  220.  * @sb_free_security:
  221.  *    Deallocate and clear the sb->s_security field.
  222.  *    @sb contains the super_block structure to be modified.
  223.  * @sb_statfs:
  224.  *    Check permission before obtaining filesystem statistics for the @mnt
  225.  *    mountpoint.
  226.  *    @dentry is a handle on the superblock for the filesystem.
  227.  *    Return 0 if permission is granted.
  228.  * @sb_mount:
  229.  *    Check permission before an object specified by @dev_name is mounted on
  230.  *    the mount point named by @nd.  For an ordinary mount, @dev_name
  231.  *    identifies a device if the file system type requires a device.  For a
  232.  *    remount (@flags & MS_REMOUNT), @dev_name is irrelevant.  For a
  233.  *    loopback/bind mount (@flags & MS_BIND), @dev_name identifies the
  234.  *    pathname of the object being mounted.
  235.  *    @dev_name contains the name for object being mounted.
  236.  *    @path contains the path for mount point object.
  237.  *    @type contains the filesystem type.
  238.  *    @flags contains the mount flags.
  239.  *    @data contains the filesystem-specific data.
  240.  *    Return 0 if permission is granted.
  241.  * @sb_copy_data:
  242.  *    Allow mount option data to be copied prior to parsing by the filesystem,
  243.  *    so that the security module can extract security-specific mount
  244.  *    options cleanly (a filesystem may modify the data e.g. with strsep()).
  245.  *    This also allows the original mount data to be stripped of security-
  246.  *    specific options to avoid having to make filesystems aware of them.
  247.  *    @type the type of filesystem being mounted.
  248.  *    @orig the original mount data copied from userspace.
  249.  *    @copy copied data which will be passed to the security module.
  250.  *    Returns 0 if the copy was successful.
  251.  * @sb_check_sb:
  252.  *    Check permission before the device with superblock @mnt->sb is mounted
  253.  *    on the mount point named by @nd.
  254.  *    @mnt contains the vfsmount for device being mounted.
  255.  *    @path contains the path for the mount point.
  256.  *    Return 0 if permission is granted.
  257.  * @sb_umount:
  258.  *    Check permission before the @mnt file system is unmounted.
  259.  *    @mnt contains the mounted file system.
  260.  *    @flags contains the unmount flags, e.g. MNT_FORCE.
  261.  *    Return 0 if permission is granted.
  262.  * @sb_umount_close:
  263.  *    Close any files in the @mnt mounted filesystem that are held open by
  264.  *    the security module.  This hook is called during an umount operation
  265.  *    prior to checking whether the filesystem is still busy.
  266.  *    @mnt contains the mounted filesystem.
  267.  * @sb_umount_busy:
  268.  *    Handle a failed umount of the @mnt mounted filesystem, e.g.  re-opening
  269.  *    any files that were closed by umount_close.  This hook is called during
  270.  *    an umount operation if the umount fails after a call to the
  271.  *    umount_close hook.
  272.  *    @mnt contains the mounted filesystem.
  273.  * @sb_post_remount:
  274.  *    Update the security module's state when a filesystem is remounted.
  275.  *    This hook is only called if the remount was successful.
  276.  *    @mnt contains the mounted file system.
  277.  *    @flags contains the new filesystem flags.
  278.  *    @data contains the filesystem-specific data.
  279.  * @sb_post_addmount:
  280.  *    Update the security module's state when a filesystem is mounted.
  281.  *    This hook is called any time a mount is successfully grafetd to
  282.  *    the tree.
  283.  *    @mnt contains the mounted filesystem.
  284.  *    @mountpoint contains the path for the mount point.
  285.  * @sb_pivotroot:
  286.  *    Check permission before pivoting the root filesystem.
  287.  *    @old_path contains the path for the new location of the current root (put_old).
  288.  *    @new_path contains the path for the new root (new_root).
  289.  *    Return 0 if permission is granted.
  290.  * @sb_post_pivotroot:
  291.  *    Update module state after a successful pivot.
  292.  *    @old_path contains the path for the old root.
  293.  *    @new_path contains the path for the new root.
  294.  * @sb_set_mnt_opts:
  295.  *    Set the security relevant mount options used for a superblock
  296.  *    @sb the superblock to set security mount options for
  297.  *    @opts binary data structure containing all lsm mount data
  298.  * @sb_clone_mnt_opts:
  299.  *    Copy all security options from a given superblock to another
  300.  *    @oldsb old superblock which contain information to clone
  301.  *    @newsb new superblock which needs filled in
  302.  * @sb_parse_opts_str:
  303.  *    Parse a string of security data filling in the opts structure
  304.  *    @options string containing all mount options known by the LSM
  305.  *    @opts binary data structure usable by the LSM
  306.  *
  307.  * Security hooks for inode operations.
  308.  *
  309.  * @inode_alloc_security:
  310.  *    Allocate and attach a security structure to @inode->i_security.  The
  311.  *    i_security field is initialized to NULL when the inode structure is
  312.  *    allocated.
  313.  *    @inode contains the inode structure.
  314.  *    Return 0 if operation was successful.
  315.  * @inode_free_security:
  316.  *    @inode contains the inode structure.
  317.  *    Deallocate the inode security structure and set @inode->i_security to
  318.  *    NULL.
  319.  * @inode_init_security:
  320.  *    Obtain the security attribute name suffix and value to set on a newly
  321.  *    created inode and set up the incore security field for the new inode.
  322.  *    This hook is called by the fs code as part of the inode creation
  323.  *    transaction and provides for atomic labeling of the inode, unlike
  324.  *    the post_create/mkdir/... hooks called by the VFS.  The hook function
  325.  *    is expected to allocate the name and value via kmalloc, with the caller
  326.  *    being responsible for calling kfree after using them.
  327.  *    If the security module does not use security attributes or does
  328.  *    not wish to put a security attribute on this particular inode,
  329.  *    then it should return -EOPNOTSUPP to skip this processing.
  330.  *    @inode contains the inode structure of the newly created inode.
  331.  *    @dir contains the inode structure of the parent directory.
  332.  *    @name will be set to the allocated name suffix (e.g. selinux).
  333.  *    @value will be set to the allocated attribute value.
  334.  *    @len will be set to the length of the value.
  335.  *    Returns 0 if @name and @value have been successfully set,
  336.  *        -EOPNOTSUPP if no security attribute is needed, or
  337.  *        -ENOMEM on memory allocation failure.
  338.  * @inode_create:
  339.  *    Check permission to create a regular file.
  340.  *    @dir contains inode structure of the parent of the new file.
  341.  *    @dentry contains the dentry structure for the file to be created.
  342.  *    @mnt is the vfsmount corresponding to @dentry (may be NULL).
  343.  *    @mode contains the file mode of the file to be created.
  344.  *    Return 0 if permission is granted.
  345.  * @inode_link:
  346.  *    Check permission before creating a new hard link to a file.
  347.  *    @old_dentry contains the dentry structure for an existing link to the file.
  348.  *    @old_mnt is the vfsmount corresponding to @old_dentry (may be NULL).
  349.  *    @dir contains the inode structure of the parent directory of the new link.
  350.  *    @new_dentry contains the dentry structure for the new link.
  351.  *    @new_mnt is the vfsmount corresponding to @new_dentry (may be NULL).
  352.  *    Return 0 if permission is granted.
  353.  * @inode_unlink:
  354.  *    Check the permission to remove a hard link to a file.
  355.  *    @dir contains the inode structure of parent directory of the file.
  356.  *    @dentry contains the dentry structure for file to be unlinked.
  357.  *    @mnt is the vfsmount corresponding to @dentry (may be NULL).
  358.  *    Return 0 if permission is granted.
  359.  * @inode_symlink:
  360.  *    Check the permission to create a symbolic link to a file.
  361.  *    @dir contains the inode structure of parent directory of the symbolic link.
  362.  *    @dentry contains the dentry structure of the symbolic link.
  363.  *    @mnt is the vfsmount corresponding to @dentry (may be NULL).
  364.  *    @old_name contains the pathname of file.
  365.  *    Return 0 if permission is granted.
  366.  * @inode_mkdir:
  367.  *    Check permissions to create a new directory in the existing directory
  368.  *    associated with inode strcture @dir.
  369.  *    @dir containst the inode structure of parent of the directory to be created.
  370.  *    @dentry contains the dentry structure of new directory.
  371.  *    @mnt is the vfsmount corresponding to @dentry (may be NULL).
  372.  *    @mode contains the mode of new directory.
  373.  *    Return 0 if permission is granted.
  374.  * @inode_rmdir:
  375.  *    Check the permission to remove a directory.
  376.  *    @dir contains the inode structure of parent of the directory to be removed.
  377.  *    @dentry contains the dentry structure of directory to be removed.
  378.  *    @mnt is the vfsmount corresponding to @dentry (may be NULL).
  379.  *    Return 0 if permission is granted.
  380.  * @inode_mknod:
  381.  *    Check permissions when creating a special file (or a socket or a fifo
  382.  *    file created via the mknod system call).  Note that if mknod operation
  383.  *    is being done for a regular file, then the create hook will be called
  384.  *    and not this hook.
  385.  *    @dir contains the inode structure of parent of the new file.
  386.  *    @dentry contains the dentry structure of the new file.
  387.  *    @mnt is the vfsmount corresponding to @dentry (may be NULL).
  388.  *    @mode contains the mode of the new file.
  389.  *    @dev contains the device number.
  390.  *    Return 0 if permission is granted.
  391.  * @inode_rename:
  392.  *    Check for permission to rename a file or directory.
  393.  *    @old_dir contains the inode structure for parent of the old link.
  394.  *    @old_dentry contains the dentry structure of the old link.
  395.  *    @old_mnt is the vfsmount corresponding to @old_dentry (may be NULL).
  396.  *    @new_dir contains the inode structure for parent of the new link.
  397.  *    @new_dentry contains the dentry structure of the new link.
  398.  *    @new_mnt is the vfsmount corresponding to @new_dentry (may be NULL).
  399.  *    Return 0 if permission is granted.
  400.  * @inode_readlink:
  401.  *    Check the permission to read the symbolic link.
  402.  *    @dentry contains the dentry structure for the file link.
  403.  *    @mnt is the vfsmount corresponding to @dentry (may be NULL).
  404.  *    Return 0 if permission is granted.
  405.  * @inode_follow_link:
  406.  *    Check permission to follow a symbolic link when looking up a pathname.
  407.  *    @dentry contains the dentry structure for the link.
  408.  *    @nd contains the nameidata structure for the parent directory.
  409.  *    Return 0 if permission is granted.
  410.  * @inode_permission:
  411.  *    Check permission before accessing an inode.  This hook is called by the
  412.  *    existing Linux permission function, so a security module can use it to
  413.  *    provide additional checking for existing Linux permission checks.
  414.  *    Notice that this hook is called when a file is opened (as well as many
  415.  *    other operations), whereas the file_security_ops permission hook is
  416.  *    called when the actual read/write operations are performed.
  417.  *    @inode contains the inode structure to check.
  418.  *    @mask contains the permission mask.
  419.  *    @nd contains the nameidata (may be NULL).
  420.  *    Return 0 if permission is granted.
  421.  * @inode_setattr:
  422.  *    Check permission before setting file attributes.  Note that the kernel
  423.  *    call to notify_change is performed from several locations, whenever
  424.  *    file attributes change (such as when a file is truncated, chown/chmod
  425.  *    operations, transferring disk quotas, etc).
  426.  *    @dentry contains the dentry structure for the file.
  427.  *    @mnt is the vfsmount corresponding to @dentry (may be NULL).
  428.  *    @attr is the iattr structure containing the new file attributes.
  429.  *    Return 0 if permission is granted.
  430.  * @inode_getattr:
  431.  *    Check permission before obtaining file attributes.
  432.  *    @mnt is the vfsmount where the dentry was looked up
  433.  *    @dentry contains the dentry structure for the file.
  434.  *    Return 0 if permission is granted.
  435.  * @inode_delete:
  436.  *    @inode contains the inode structure for deleted inode.
  437.  *    This hook is called when a deleted inode is released (i.e. an inode
  438.  *    with no hard links has its use count drop to zero).  A security module
  439.  *    can use this hook to release any persistent label associated with the
  440.  *    inode.
  441.  * @inode_setxattr:
  442.  *    Check permission before setting the extended attributes
  443.  *     @value identified by @name for @dentry and @mnt.
  444.  *    Return 0 if permission is granted.
  445.  * @inode_post_setxattr:
  446.  *    Update inode security field after successful setxattr operation.
  447.  *     @value identified by @name for @dentry and @mnt.
  448.  * @inode_getxattr:
  449.  *    Check permission before obtaining the extended attributes
  450.  *     identified by @name for @dentry and @mnt.
  451.  *    Return 0 if permission is granted.
  452.  * @inode_listxattr:
  453.  *    Check permission before obtaining the list of extended attribute
  454.  *     names for @dentry and @mnt.
  455.  *    Return 0 if permission is granted.
  456.  * @inode_removexattr:
  457.  *    Check permission before removing the extended attribute
  458.  *    identified by @name for @dentry.
  459.  *    Return 0 if permission is granted.
  460.  * @inode_getsecurity:
  461.  *    Retrieve a copy of the extended attribute representation of the
  462.  *    security label associated with @name for @inode via @buffer.  Note that
  463.  *    @name is the remainder of the attribute name after the security prefix
  464.  *    has been removed. @alloc is used to specify of the call should return a
  465.  *    value via the buffer or just the value length Return size of buffer on
  466.  *    success.
  467.  * @inode_setsecurity:
  468.  *    Set the security label associated with @name for @inode from the
  469.  *    extended attribute value @value.  @size indicates the size of the
  470.  *    @value in bytes.  @flags may be XATTR_CREATE, XATTR_REPLACE, or 0.
  471.  *    Note that @name is the remainder of the attribute name after the
  472.  *    security. prefix has been removed.
  473.  *    Return 0 on success.
  474.  * @inode_listsecurity:
  475.  *    Copy the extended attribute names for the security labels
  476.  *    associated with @inode into @buffer.  The maximum size of @buffer
  477.  *    is specified by @buffer_size.  @buffer may be NULL to request
  478.  *    the size of the buffer required.
  479.  *    Returns number of bytes used/required on success.
  480.  * @inode_need_killpriv:
  481.  *    Called when an inode has been changed.
  482.  *    @dentry is the dentry being changed.
  483.  *    Return <0 on error to abort the inode change operation.
  484.  *    Return 0 if inode_killpriv does not need to be called.
  485.  *    Return >0 if inode_killpriv does need to be called.
  486.  * @inode_killpriv:
  487.  *    The setuid bit is being removed.  Remove similar security labels.
  488.  *    Called with the dentry->d_inode->i_mutex held.
  489.  *    @dentry is the dentry being changed.
  490.  *    Return 0 on success.  If error is returned, then the operation
  491.  *    causing setuid bit removal is failed.
  492.  * @inode_getsecid:
  493.  *    Get the secid associated with the node.
  494.  *    @inode contains a pointer to the inode.
  495.  *    @secid contains a pointer to the location where result will be saved.
  496.  *    In case of failure, @secid will be set to zero.
  497.  *
  498.  * Security hooks for file operations
  499.  *
  500.  * @file_permission:
  501.  *    Check file permissions before accessing an open file.  This hook is
  502.  *    called by various operations that read or write files.  A security
  503.  *    module can use this hook to perform additional checking on these
  504.  *    operations, e.g.  to revalidate permissions on use to support privilege
  505.  *    bracketing or policy changes.  Notice that this hook is used when the
  506.  *    actual read/write operations are performed, whereas the
  507.  *    inode_security_ops hook is called when a file is opened (as well as
  508.  *    many other operations).
  509.  *    Caveat:  Although this hook can be used to revalidate permissions for
  510.  *    various system call operations that read or write files, it does not
  511.  *    address the revalidation of permissions for memory-mapped files.
  512.  *    Security modules must handle this separately if they need such
  513.  *    revalidation.
  514.  *    @file contains the file structure being accessed.
  515.  *    @mask contains the requested permissions.
  516.  *    Return 0 if permission is granted.
  517.  * @file_alloc_security:
  518.  *    Allocate and attach a security structure to the file->f_security field.
  519.  *    The security field is initialized to NULL when the structure is first
  520.  *    created.
  521.  *    @file contains the file structure to secure.
  522.  *    Return 0 if the hook is successful and permission is granted.
  523.  * @file_free_security:
  524.  *    Deallocate and free any security structures stored in file->f_security.
  525.  *    @file contains the file structure being modified.
  526.  * @file_ioctl:
  527.  *    @file contains the file structure.
  528.  *    @cmd contains the operation to perform.
  529.  *    @arg contains the operational arguments.
  530.  *    Check permission for an ioctl operation on @file.  Note that @arg can
  531.  *    sometimes represents a user space pointer; in other cases, it may be a
  532.  *    simple integer value.  When @arg represents a user space pointer, it
  533.  *    should never be used by the security module.
  534.  *    Return 0 if permission is granted.
  535.  * @file_mmap :
  536.  *    Check permissions for a mmap operation.  The @file may be NULL, e.g.
  537.  *    if mapping anonymous memory.
  538.  *    @file contains the file structure for file to map (may be NULL).
  539.  *    @reqprot contains the protection requested by the application.
  540.  *    @prot contains the protection that will be applied by the kernel.
  541.  *    @flags contains the operational flags.
  542.  *    Return 0 if permission is granted.
  543.  * @file_mprotect:
  544.  *    Check permissions before changing memory access permissions.
  545.  *    @vma contains the memory region to modify.
  546.  *    @reqprot contains the protection requested by the application.
  547.  *    @prot contains the protection that will be applied by the kernel.
  548.  *    Return 0 if permission is granted.
  549.  * @file_lock:
  550.  *    Check permission before performing file locking operations.
  551.  *    Note: this hook mediates both flock and fcntl style locks.
  552.  *    @file contains the file structure.
  553.  *    @cmd contains the posix-translated lock operation to perform
  554.  *    (e.g. F_RDLCK, F_WRLCK).
  555.  *    Return 0 if permission is granted.
  556.  * @file_fcntl:
  557.  *    Check permission before allowing the file operation specified by @cmd
  558.  *    from being performed on the file @file.  Note that @arg can sometimes
  559.  *    represents a user space pointer; in other cases, it may be a simple
  560.  *    integer value.  When @arg represents a user space pointer, it should
  561.  *    never be used by the security module.
  562.  *    @file contains the file structure.
  563.  *    @cmd contains the operation to be performed.
  564.  *    @arg contains the operational arguments.
  565.  *    Return 0 if permission is granted.
  566.  * @file_set_fowner:
  567.  *    Save owner security information (typically from current->security) in
  568.  *    file->f_security for later use by the send_sigiotask hook.
  569.  *    @file contains the file structure to update.
  570.  *    Return 0 on success.
  571.  * @file_send_sigiotask:
  572.  *    Check permission for the file owner @fown to send SIGIO or SIGURG to the
  573.  *    process @tsk.  Note that this hook is sometimes called from interrupt.
  574.  *    Note that the fown_struct, @fown, is never outside the context of a
  575.  *    struct file, so the file structure (and associated security information)
  576.  *    can always be obtained:
  577.  *        container_of(fown, struct file, f_owner)
  578.  *    @tsk contains the structure of task receiving signal.
  579.  *    @fown contains the file owner information.
  580.  *    @sig is the signal that will be sent.  When 0, kernel sends SIGIO.
  581.  *    Return 0 if permission is granted.
  582.  * @file_receive:
  583.  *    This hook allows security modules to control the ability of a process
  584.  *    to receive an open file descriptor via socket IPC.
  585.  *    @file contains the file structure being received.
  586.  *    Return 0 if permission is granted.
  587.  *
  588.  * Security hook for dentry
  589.  *
  590.  * @dentry_open
  591.  *    Save open-time permission checking state for later use upon
  592.  *    file_permission, and recheck access if anything has changed
  593.  *    since inode_permission.
  594.  *
  595.  * Security hook for path
  596.  *
  597.  * @path_permission:
  598.  *    Check permission before accessing a path.  This hook is called by the
  599.  *    existing Linux permission function, so a security module can use it to
  600.  *    provide additional checking for existing Linux permission checks.
  601.  *    Notice that this hook is called when a file is opened (as well as many
  602.  *    other operations), whereas the file_security_ops permission hook is
  603.  *    called when the actual read/write operations are performed. This
  604.  *    hook is optional and if absent, inode_permission will be substituted.
  605.  *    @path contains the path structure to check.
  606.  *    @mask contains the permission mask.
  607.  *    Return 0 if permission is granted.
  608.  
  609.  * Security hooks for task operations.
  610.  *
  611.  * @task_create:
  612.  *    Check permission before creating a child process.  See the clone(2)
  613.  *    manual page for definitions of the @clone_flags.
  614.  *    @clone_flags contains the flags indicating what should be shared.
  615.  *    Return 0 if permission is granted.
  616.  * @task_alloc_security:
  617.  *    @p contains the task_struct for child process.
  618.  *    Allocate and attach a security structure to the p->security field. The
  619.  *    security field is initialized to NULL when the task structure is
  620.  *    allocated.
  621.  *    Return 0 if operation was successful.
  622.  * @task_free_security:
  623.  *    @p contains the task_struct for process.
  624.  *    Deallocate and clear the p->security field.
  625.  * @task_setuid:
  626.  *    Check permission before setting one or more of the user identity
  627.  *    attributes of the current process.  The @flags parameter indicates
  628.  *    which of the set*uid system calls invoked this hook and how to
  629.  *    interpret the @id0, @id1, and @id2 parameters.  See the LSM_SETID
  630.  *    definitions at the beginning of this file for the @flags values and
  631.  *    their meanings.
  632.  *    @id0 contains a uid.
  633.  *    @id1 contains a uid.
  634.  *    @id2 contains a uid.
  635.  *    @flags contains one of the LSM_SETID_* values.
  636.  *    Return 0 if permission is granted.
  637.  * @task_post_setuid:
  638.  *    Update the module's state after setting one or more of the user
  639.  *    identity attributes of the current process.  The @flags parameter
  640.  *    indicates which of the set*uid system calls invoked this hook.  If
  641.  *    @flags is LSM_SETID_FS, then @old_ruid is the old fs uid and the other
  642.  *    parameters are not used.
  643.  *    @old_ruid contains the old real uid (or fs uid if LSM_SETID_FS).
  644.  *    @old_euid contains the old effective uid (or -1 if LSM_SETID_FS).
  645.  *    @old_suid contains the old saved uid (or -1 if LSM_SETID_FS).
  646.  *    @flags contains one of the LSM_SETID_* values.
  647.  *    Return 0 on success.
  648.  * @task_setgid:
  649.  *    Check permission before setting one or more of the group identity
  650.  *    attributes of the current process.  The @flags parameter indicates
  651.  *    which of the set*gid system calls invoked this hook and how to
  652.  *    interpret the @id0, @id1, and @id2 parameters.  See the LSM_SETID
  653.  *    definitions at the beginning of this file for the @flags values and
  654.  *    their meanings.
  655.  *    @id0 contains a gid.
  656.  *    @id1 contains a gid.
  657.  *    @id2 contains a gid.
  658.  *    @flags contains one of the LSM_SETID_* values.
  659.  *    Return 0 if permission is granted.
  660.  * @task_setpgid:
  661.  *    Check permission before setting the process group identifier of the
  662.  *    process @p to @pgid.
  663.  *    @p contains the task_struct for process being modified.
  664.  *    @pgid contains the new pgid.
  665.  *    Return 0 if permission is granted.
  666.  * @task_getpgid:
  667.  *    Check permission before getting the process group identifier of the
  668.  *    process @p.
  669.  *    @p contains the task_struct for the process.
  670.  *    Return 0 if permission is granted.
  671.  * @task_getsid:
  672.  *    Check permission before getting the session identifier of the process
  673.  *    @p.
  674.  *    @p contains the task_struct for the process.
  675.  *    Return 0 if permission is granted.
  676.  * @task_getsecid:
  677.  *    Retrieve the security identifier of the process @p.
  678.  *    @p contains the task_struct for the process and place is into @secid.
  679.  *    In case of failure, @secid will be set to zero.
  680.  *
  681.  * @task_setgroups:
  682.  *    Check permission before setting the supplementary group set of the
  683.  *    current process.
  684.  *    @group_info contains the new group information.
  685.  *    Return 0 if permission is granted.
  686.  * @task_setnice:
  687.  *    Check permission before setting the nice value of @p to @nice.
  688.  *    @p contains the task_struct of process.
  689.  *    @nice contains the new nice value.
  690.  *    Return 0 if permission is granted.
  691.  * @task_setioprio
  692.  *    Check permission before setting the ioprio value of @p to @ioprio.
  693.  *    @p contains the task_struct of process.
  694.  *    @ioprio contains the new ioprio value
  695.  *    Return 0 if permission is granted.
  696.  * @task_getioprio
  697.  *    Check permission before getting the ioprio value of @p.
  698.  *    @p contains the task_struct of process.
  699.  *    Return 0 if permission is granted.
  700.  * @task_setrlimit:
  701.  *    Check permission before setting the resource limits of the current
  702.  *    process for @resource to @new_rlim.  The old resource limit values can
  703.  *    be examined by dereferencing (current->signal->rlim + resource).
  704.  *    @resource contains the resource whose limit is being set.
  705.  *    @new_rlim contains the new limits for @resource.
  706.  *    Return 0 if permission is granted.
  707.  * @task_setscheduler:
  708.  *    Check permission before setting scheduling policy and/or parameters of
  709.  *    process @p based on @policy and @lp.
  710.  *    @p contains the task_struct for process.
  711.  *    @policy contains the scheduling policy.
  712.  *    @lp contains the scheduling parameters.
  713.  *    Return 0 if permission is granted.
  714.  * @task_getscheduler:
  715.  *    Check permission before obtaining scheduling information for process
  716.  *    @p.
  717.  *    @p contains the task_struct for process.
  718.  *    Return 0 if permission is granted.
  719.  * @task_movememory
  720.  *    Check permission before moving memory owned by process @p.
  721.  *    @p contains the task_struct for process.
  722.  *    Return 0 if permission is granted.
  723.  * @task_kill:
  724.  *    Check permission before sending signal @sig to @p.  @info can be NULL,
  725.  *    the constant 1, or a pointer to a siginfo structure.  If @info is 1 or
  726.  *    SI_FROMKERNEL(info) is true, then the signal should be viewed as coming
  727.  *    from the kernel and should typically be permitted.
  728.  *    SIGIO signals are handled separately by the send_sigiotask hook in
  729.  *    file_security_ops.
  730.  *    @p contains the task_struct for process.
  731.  *    @info contains the signal information.
  732.  *    @sig contains the signal value.
  733.  *    @secid contains the sid of the process where the signal originated
  734.  *    Return 0 if permission is granted.
  735.  * @task_wait:
  736.  *    Check permission before allowing a process to reap a child process @p
  737.  *    and collect its status information.
  738.  *    @p contains the task_struct for process.
  739.  *    Return 0 if permission is granted.
  740.  * @task_prctl:
  741.  *    Check permission before performing a process control operation on the
  742.  *    current process.
  743.  *    @option contains the operation.
  744.  *    @arg2 contains a argument.
  745.  *    @arg3 contains a argument.
  746.  *    @arg4 contains a argument.
  747.  *    @arg5 contains a argument.
  748.  *      @rc_p contains a pointer to communicate back the forced return code
  749.  *    Return 0 if permission is granted, and non-zero if the security module
  750.  *      has taken responsibility (setting *rc_p) for the prctl call.
  751.  * @task_reparent_to_init:
  752.  *    Set the security attributes in @p->security for a kernel thread that
  753.  *    is being reparented to the init task.
  754.  *    @p contains the task_struct for the kernel thread.
  755.  * @task_to_inode:
  756.  *    Set the security attributes for an inode based on an associated task's
  757.  *    security attributes, e.g. for /proc/pid inodes.
  758.  *    @p contains the task_struct for the task.
  759.  *    @inode contains the inode structure for the inode.
  760.  *
  761.  * Security hooks for Netlink messaging.
  762.  *
  763.  * @netlink_send:
  764.  *    Save security information for a netlink message so that permission
  765.  *    checking can be performed when the message is processed.  The security
  766.  *    information can be saved using the eff_cap field of the
  767.  *    netlink_skb_parms structure.  Also may be used to provide fine
  768.  *    grained control over message transmission.
  769.  *    @sk associated sock of task sending the message.,
  770.  *    @skb contains the sk_buff structure for the netlink message.
  771.  *    Return 0 if the information was successfully saved and message
  772.  *    is allowed to be transmitted.
  773.  * @netlink_recv:
  774.  *    Check permission before processing the received netlink message in
  775.  *    @skb.
  776.  *    @skb contains the sk_buff structure for the netlink message.
  777.  *    @cap indicates the capability required
  778.  *    Return 0 if permission is granted.
  779.  *
  780.  * Security hooks for Unix domain networking.
  781.  *
  782.  * @unix_stream_connect:
  783.  *    Check permissions before establishing a Unix domain stream connection
  784.  *    between @sock and @other.
  785.  *    @sock contains the socket structure.
  786.  *    @other contains the peer socket structure.
  787.  *    Return 0 if permission is granted.
  788.  * @unix_may_send:
  789.  *    Check permissions before connecting or sending datagrams from @sock to
  790.  *    @other.
  791.  *    @sock contains the socket structure.
  792.  *    @sock contains the peer socket structure.
  793.  *    Return 0 if permission is granted.
  794.  *
  795.  * The @unix_stream_connect and @unix_may_send hooks were necessary because
  796.  * Linux provides an alternative to the conventional file name space for Unix
  797.  * domain sockets.  Whereas binding and connecting to sockets in the file name
  798.  * space is mediated by the typical file permissions (and caught by the mknod
  799.  * and permission hooks in inode_security_ops), binding and connecting to
  800.  * sockets in the abstract name space is completely unmediated.  Sufficient
  801.  * control of Unix domain sockets in the abstract name space isn't possible
  802.  * using only the socket layer hooks, since we need to know the actual target
  803.  * socket, which is not looked up until we are inside the af_unix code.
  804.  *
  805.  * Security hooks for socket operations.
  806.  *
  807.  * @socket_create:
  808.  *    Check permissions prior to creating a new socket.
  809.  *    @family contains the requested protocol family.
  810.  *    @type contains the requested communications type.
  811.  *    @protocol contains the requested protocol.
  812.  *    @kern set to 1 if a kernel socket.
  813.  *    Return 0 if permission is granted.
  814.  * @socket_post_create:
  815.  *    This hook allows a module to update or allocate a per-socket security
  816.  *    structure. Note that the security field was not added directly to the
  817.  *    socket structure, but rather, the socket security information is stored
  818.  *    in the associated inode.  Typically, the inode alloc_security hook will
  819.  *    allocate and and attach security information to
  820.  *    sock->inode->i_security.  This hook may be used to update the
  821.  *    sock->inode->i_security field with additional information that wasn't
  822.  *    available when the inode was allocated.
  823.  *    @sock contains the newly created socket structure.
  824.  *    @family contains the requested protocol family.
  825.  *    @type contains the requested communications type.
  826.  *    @protocol contains the requested protocol.
  827.  *    @kern set to 1 if a kernel socket.
  828.  * @socket_bind:
  829.  *    Check permission before socket protocol layer bind operation is
  830.  *    performed and the socket @sock is bound to the address specified in the
  831.  *    @address parameter.
  832.  *    @sock contains the socket structure.
  833.  *    @address contains the address to bind to.
  834.  *    @addrlen contains the length of address.
  835.  *    Return 0 if permission is granted.
  836.  * @socket_connect:
  837.  *    Check permission before socket protocol layer connect operation
  838.  *    attempts to connect socket @sock to a remote address, @address.
  839.  *    @sock contains the socket structure.
  840.  *    @address contains the address of remote endpoint.
  841.  *    @addrlen contains the length of address.
  842.  *    Return 0 if permission is granted.
  843.  * @socket_listen:
  844.  *    Check permission before socket protocol layer listen operation.
  845.  *    @sock contains the socket structure.
  846.  *    @backlog contains the maximum length for the pending connection queue.
  847.  *    Return 0 if permission is granted.
  848.  * @socket_accept:
  849.  *    Check permission before accepting a new connection.  Note that the new
  850.  *    socket, @newsock, has been created and some information copied to it,
  851.  *    but the accept operation has not actually been performed.
  852.  *    @sock contains the listening socket structure.
  853.  *    @newsock contains the newly created server socket for connection.
  854.  *    Return 0 if permission is granted.
  855.  * @socket_post_accept:
  856.  *    This hook allows a security module to copy security
  857.  *    information into the newly created socket's inode.
  858.  *    @sock contains the listening socket structure.
  859.  *    @newsock contains the newly created server socket for connection.
  860.  * @socket_sendmsg:
  861.  *    Check permission before transmitting a message to another socket.
  862.  *    @sock contains the socket structure.
  863.  *    @msg contains the message to be transmitted.
  864.  *    @size contains the size of message.
  865.  *    Return 0 if permission is granted.
  866.  * @socket_recvmsg:
  867.  *    Check permission before receiving a message from a socket.
  868.  *    @sock contains the socket structure.
  869.  *    @msg contains the message structure.
  870.  *    @size contains the size of message structure.
  871.  *    @flags contains the operational flags.
  872.  *    Return 0 if permission is granted.
  873.  * @socket_getsockname:
  874.  *    Check permission before the local address (name) of the socket object
  875.  *    @sock is retrieved.
  876.  *    @sock contains the socket structure.
  877.  *    Return 0 if permission is granted.
  878.  * @socket_getpeername:
  879.  *    Check permission before the remote address (name) of a socket object
  880.  *    @sock is retrieved.
  881.  *    @sock contains the socket structure.
  882.  *    Return 0 if permission is granted.
  883.  * @socket_getsockopt:
  884.  *    Check permissions before retrieving the options associated with socket
  885.  *    @sock.
  886.  *    @sock contains the socket structure.
  887.  *    @level contains the protocol level to retrieve option from.
  888.  *    @optname contains the name of option to retrieve.
  889.  *    Return 0 if permission is granted.
  890.  * @socket_setsockopt:
  891.  *    Check permissions before setting the options associated with socket
  892.  *    @sock.
  893.  *    @sock contains the socket structure.
  894.  *    @level contains the protocol level to set options for.
  895.  *    @optname contains the name of the option to set.
  896.  *    Return 0 if permission is granted.
  897.  * @socket_shutdown:
  898.  *    Checks permission before all or part of a connection on the socket
  899.  *    @sock is shut down.
  900.  *    @sock contains the socket structure.
  901.  *    @how contains the flag indicating how future sends and receives are handled.
  902.  *    Return 0 if permission is granted.
  903.  * @socket_sock_rcv_skb:
  904.  *    Check permissions on incoming network packets.  This hook is distinct
  905.  *    from Netfilter's IP input hooks since it is the first time that the
  906.  *    incoming sk_buff @skb has been associated with a particular socket, @sk.
  907.  *    @sk contains the sock (not socket) associated with the incoming sk_buff.
  908.  *    @skb contains the incoming network data.
  909.  * @socket_getpeersec_stream:
  910.  *    This hook allows the security module to provide peer socket security
  911.  *    state for unix or connected tcp sockets to userspace via getsockopt
  912.  *    SO_GETPEERSEC.  For tcp sockets this can be meaningful if the
  913.  *    socket is associated with an ipsec SA.
  914.  *    @sock is the local socket.
  915.  *    @optval userspace memory where the security state is to be copied.
  916.  *    @optlen userspace int where the module should copy the actual length
  917.  *    of the security state.
  918.  *    @len as input is the maximum length to copy to userspace provided
  919.  *    by the caller.
  920.  *    Return 0 if all is well, otherwise, typical getsockopt return
  921.  *    values.
  922.  * @socket_getpeersec_dgram:
  923.  *    This hook allows the security module to provide peer socket security
  924.  *    state for udp sockets on a per-packet basis to userspace via
  925.  *    getsockopt SO_GETPEERSEC.  The application must first have indicated
  926.  *    the IP_PASSSEC option via getsockopt.  It can then retrieve the
  927.  *    security state returned by this hook for a packet via the SCM_SECURITY
  928.  *    ancillary message type.
  929.  *    @skb is the skbuff for the packet being queried
  930.  *    @secdata is a pointer to a buffer in which to copy the security data
  931.  *    @seclen is the maximum length for @secdata
  932.  *    Return 0 on success, error on failure.
  933.  * @sk_alloc_security:
  934.  *    Allocate and attach a security structure to the sk->sk_security field,
  935.  *    which is used to copy security attributes between local stream sockets.
  936.  * @sk_free_security:
  937.  *    Deallocate security structure.
  938.  * @sk_clone_security:
  939.  *    Clone/copy security structure.
  940.  * @sk_getsecid:
  941.  *    Retrieve the LSM-specific secid for the sock to enable caching of network
  942.  *    authorizations.
  943.  * @sock_graft:
  944.  *    Sets the socket's isec sid to the sock's sid.
  945.  * @inet_conn_request:
  946.  *    Sets the openreq's sid to socket's sid with MLS portion taken from peer sid.
  947.  * @inet_csk_clone:
  948.  *    Sets the new child socket's sid to the openreq sid.
  949.  * @inet_conn_established:
  950.  *    Sets the connection's peersid to the secmark on skb.
  951.  * @req_classify_flow:
  952.  *    Sets the flow's sid to the openreq sid.
  953.  *
  954.  * Security hooks for XFRM operations.
  955.  *
  956.  * @xfrm_policy_alloc_security:
  957.  *    @ctxp is a pointer to the xfrm_sec_ctx being added to Security Policy
  958.  *    Database used by the XFRM system.
  959.  *    @sec_ctx contains the security context information being provided by
  960.  *    the user-level policy update program (e.g., setkey).
  961.  *    Allocate a security structure to the xp->security field; the security
  962.  *    field is initialized to NULL when the xfrm_policy is allocated.
  963.  *    Return 0 if operation was successful (memory to allocate, legal context)
  964.  * @xfrm_policy_clone_security:
  965.  *    @old_ctx contains an existing xfrm_sec_ctx.
  966.  *    @new_ctxp contains a new xfrm_sec_ctx being cloned from old.
  967.  *    Allocate a security structure in new_ctxp that contains the
  968.  *    information from the old_ctx structure.
  969.  *    Return 0 if operation was successful (memory to allocate).
  970.  * @xfrm_policy_free_security:
  971.  *    @ctx contains the xfrm_sec_ctx
  972.  *    Deallocate xp->security.
  973.  * @xfrm_policy_delete_security:
  974.  *    @ctx contains the xfrm_sec_ctx.
  975.  *    Authorize deletion of xp->security.
  976.  * @xfrm_state_alloc_security:
  977.  *    @x contains the xfrm_state being added to the Security Association
  978.  *    Database by the XFRM system.
  979.  *    @sec_ctx contains the security context information being provided by
  980.  *    the user-level SA generation program (e.g., setkey or racoon).
  981.  *    @secid contains the secid from which to take the mls portion of the context.
  982.  *    Allocate a security structure to the x->security field; the security
  983.  *    field is initialized to NULL when the xfrm_state is allocated. Set the
  984.  *    context to correspond to either sec_ctx or polsec, with the mls portion
  985.  *    taken from secid in the latter case.
  986.  *    Return 0 if operation was successful (memory to allocate, legal context).
  987.  * @xfrm_state_free_security:
  988.  *    @x contains the xfrm_state.
  989.  *    Deallocate x->security.
  990.  * @xfrm_state_delete_security:
  991.  *    @x contains the xfrm_state.
  992.  *    Authorize deletion of x->security.
  993.  * @xfrm_policy_lookup:
  994.  *    @ctx contains the xfrm_sec_ctx for which the access control is being
  995.  *    checked.
  996.  *    @fl_secid contains the flow security label that is used to authorize
  997.  *    access to the policy xp.
  998.  *    @dir contains the direction of the flow (input or output).
  999.  *    Check permission when a flow selects a xfrm_policy for processing
  1000.  *    XFRMs on a packet.  The hook is called when selecting either a
  1001.  *    per-socket policy or a generic xfrm policy.
  1002.  *    Return 0 if permission is granted, -ESRCH otherwise, or -errno
  1003.  *    on other errors.
  1004.  * @xfrm_state_pol_flow_match:
  1005.  *    @x contains the state to match.
  1006.  *    @xp contains the policy to check for a match.
  1007.  *    @fl contains the flow to check for a match.
  1008.  *    Return 1 if there is a match.
  1009.  * @xfrm_decode_session:
  1010.  *    @skb points to skb to decode.
  1011.  *    @secid points to the flow key secid to set.
  1012.  *    @ckall says if all xfrms used should be checked for same secid.
  1013.  *    Return 0 if ckall is zero or all xfrms used have the same secid.
  1014.  *
  1015.  * Security hooks affecting all Key Management operations
  1016.  *
  1017.  * @key_alloc:
  1018.  *    Permit allocation of a key and assign security data. Note that key does
  1019.  *    not have a serial number assigned at this point.
  1020.  *    @key points to the key.
  1021.  *    @flags is the allocation flags
  1022.  *    Return 0 if permission is granted, -ve error otherwise.
  1023.  * @key_free:
  1024.  *    Notification of destruction; free security data.
  1025.  *    @key points to the key.
  1026.  *    No return value.
  1027.  * @key_permission:
  1028.  *    See whether a specific operational right is granted to a process on a
  1029.  *    key.
  1030.  *    @key_ref refers to the key (key pointer + possession attribute bit).
  1031.  *    @context points to the process to provide the context against which to
  1032.  *    evaluate the security data on the key.
  1033.  *    @perm describes the combination of permissions required of this key.
  1034.  *    Return 1 if permission granted, 0 if permission denied and -ve it the
  1035.  *    normal permissions model should be effected.
  1036.  * @key_getsecurity:
  1037.  *    Get a textual representation of the security context attached to a key
  1038.  *    for the purposes of honouring KEYCTL_GETSECURITY.  This function
  1039.  *    allocates the storage for the NUL-terminated string and the caller
  1040.  *    should free it.
  1041.  *    @key points to the key to be queried.
  1042.  *    @_buffer points to a pointer that should be set to point to the
  1043.  *     resulting string (if no label or an error occurs).
  1044.  *    Return the length of the string (including terminating NUL) or -ve if
  1045.  *      an error.
  1046.  *    May also return 0 (and a NULL buffer pointer) if there is no label.
  1047.  *
  1048.  * Security hooks affecting all System V IPC operations.
  1049.  *
  1050.  * @ipc_permission:
  1051.  *    Check permissions for access to IPC
  1052.  *    @ipcp contains the kernel IPC permission structure
  1053.  *    @flag contains the desired (requested) permission set
  1054.  *    Return 0 if permission is granted.
  1055.  * @ipc_getsecid:
  1056.  *    Get the secid associated with the ipc object.
  1057.  *    @ipcp contains the kernel IPC permission structure.
  1058.  *    @secid contains a pointer to the location where result will be saved.
  1059.  *    In case of failure, @secid will be set to zero.
  1060.  *
  1061.  * Security hooks for individual messages held in System V IPC message queues
  1062.  * @msg_msg_alloc_security:
  1063.  *    Allocate and attach a security structure to the msg->security field.
  1064.  *    The security field is initialized to NULL when the structure is first
  1065.  *    created.
  1066.  *    @msg contains the message structure to be modified.
  1067.  *    Return 0 if operation was successful and permission is granted.
  1068.  * @msg_msg_free_security:
  1069.  *    Deallocate the security structure for this message.
  1070.  *    @msg contains the message structure to be modified.
  1071.  *
  1072.  * Security hooks for System V IPC Message Queues
  1073.  *
  1074.  * @msg_queue_alloc_security:
  1075.  *    Allocate and attach a security structure to the
  1076.  *    msq->q_perm.security field. The security field is initialized to
  1077.  *    NULL when the structure is first created.
  1078.  *    @msq contains the message queue structure to be modified.
  1079.  *    Return 0 if operation was successful and permission is granted.
  1080.  * @msg_queue_free_security:
  1081.  *    Deallocate security structure for this message queue.
  1082.  *    @msq contains the message queue structure to be modified.
  1083.  * @msg_queue_associate:
  1084.  *    Check permission when a message queue is requested through the
  1085.  *    msgget system call.  This hook is only called when returning the
  1086.  *    message queue identifier for an existing message queue, not when a
  1087.  *    new message queue is created.
  1088.  *    @msq contains the message queue to act upon.
  1089.  *    @msqflg contains the operation control flags.
  1090.  *    Return 0 if permission is granted.
  1091.  * @msg_queue_msgctl:
  1092.  *    Check permission when a message control operation specified by @cmd
  1093.  *    is to be performed on the message queue @msq.
  1094.  *    The @msq may be NULL, e.g. for IPC_INFO or MSG_INFO.
  1095.  *    @msq contains the message queue to act upon.  May be NULL.
  1096.  *    @cmd contains the operation to be performed.
  1097.  *    Return 0 if permission is granted.
  1098.  * @msg_queue_msgsnd:
  1099.  *    Check permission before a message, @msg, is enqueued on the message
  1100.  *    queue, @msq.
  1101.  *    @msq contains the message queue to send message to.
  1102.  *    @msg contains the message to be enqueued.
  1103.  *    @msqflg contains operational flags.
  1104.  *    Return 0 if permission is granted.
  1105.  * @msg_queue_msgrcv:
  1106.  *    Check permission before a message, @msg, is removed from the message
  1107.  *    queue, @msq.  The @target task structure contains a pointer to the
  1108.  *    process that will be receiving the message (not equal to the current
  1109.  *    process when inline receives are being performed).
  1110.  *    @msq contains the message queue to retrieve message from.
  1111.  *    @msg contains the message destination.
  1112.  *    @target contains the task structure for recipient process.
  1113.  *    @type contains the type of message requested.
  1114.  *    @mode contains the operational flags.
  1115.  *    Return 0 if permission is granted.
  1116.  *
  1117.  * Security hooks for System V Shared Memory Segments
  1118.  *
  1119.  * @shm_alloc_security:
  1120.  *    Allocate and attach a security structure to the shp->shm_perm.security
  1121.  *    field.  The security field is initialized to NULL when the structure is
  1122.  *    first created.
  1123.  *    @shp contains the shared memory structure to be modified.
  1124.  *    Return 0 if operation was successful and permission is granted.
  1125.  * @shm_free_security:
  1126.  *    Deallocate the security struct for this memory segment.
  1127.  *    @shp contains the shared memory structure to be modified.
  1128.  * @shm_associate:
  1129.  *    Check permission when a shared memory region is requested through the
  1130.  *    shmget system call.  This hook is only called when returning the shared
  1131.  *    memory region identifier for an existing region, not when a new shared
  1132.  *    memory region is created.
  1133.  *    @shp contains the shared memory structure to be modified.
  1134.  *    @shmflg contains the operation control flags.
  1135.  *    Return 0 if permission is granted.
  1136.  * @shm_shmctl:
  1137.  *    Check permission when a shared memory control operation specified by
  1138.  *    @cmd is to be performed on the shared memory region @shp.
  1139.  *    The @shp may be NULL, e.g. for IPC_INFO or SHM_INFO.
  1140.  *    @shp contains shared memory structure to be modified.
  1141.  *    @cmd contains the operation to be performed.
  1142.  *    Return 0 if permission is granted.
  1143.  * @shm_shmat:
  1144.  *    Check permissions prior to allowing the shmat system call to attach the
  1145.  *    shared memory segment @shp to the data segment of the calling process.
  1146.  *    The attaching address is specified by @shmaddr.
  1147.  *    @shp contains the shared memory structure to be modified.
  1148.  *    @shmaddr contains the address to attach memory region to.
  1149.  *    @shmflg contains the operational flags.
  1150.  *    Return 0 if permission is granted.
  1151.  *
  1152.  * Security hooks for System V Semaphores
  1153.  *
  1154.  * @sem_alloc_security:
  1155.  *    Allocate and attach a security structure to the sma->sem_perm.security
  1156.  *    field.  The security field is initialized to NULL when the structure is
  1157.  *    first created.
  1158.  *    @sma contains the semaphore structure
  1159.  *    Return 0 if operation was successful and permission is granted.
  1160.  * @sem_free_security:
  1161.  *    deallocate security struct for this semaphore
  1162.  *    @sma contains the semaphore structure.
  1163.  * @sem_associate:
  1164.  *    Check permission when a semaphore is requested through the semget
  1165.  *    system call.  This hook is only called when returning the semaphore
  1166.  *    identifier for an existing semaphore, not when a new one must be
  1167.  *    created.
  1168.  *    @sma contains the semaphore structure.
  1169.  *    @semflg contains the operation control flags.
  1170.  *    Return 0 if permission is granted.
  1171.  * @sem_semctl:
  1172.  *    Check permission when a semaphore operation specified by @cmd is to be
  1173.  *    performed on the semaphore @sma.  The @sma may be NULL, e.g. for
  1174.  *    IPC_INFO or SEM_INFO.
  1175.  *    @sma contains the semaphore structure.  May be NULL.
  1176.  *    @cmd contains the operation to be performed.
  1177.  *    Return 0 if permission is granted.
  1178.  * @sem_semop
  1179.  *    Check permissions before performing operations on members of the
  1180.  *    semaphore set @sma.  If the @alter flag is nonzero, the semaphore set
  1181.  *    may be modified.
  1182.  *    @sma contains the semaphore structure.
  1183.  *    @sops contains the operations to perform.
  1184.  *    @nsops contains the number of operations to perform.
  1185.  *    @alter contains the flag indicating whether changes are to be made.
  1186.  *    Return 0 if permission is granted.
  1187.  *
  1188.  * @ptrace_may_access:
  1189.  *    Check permission before allowing the current process to trace the
  1190.  *    @child process.
  1191.  *    Security modules may also want to perform a process tracing check
  1192.  *    during an execve in the set_security or apply_creds hooks of
  1193.  *    binprm_security_ops if the process is being traced and its security
  1194.  *    attributes would be changed by the execve.
  1195.  *    @child contains the task_struct structure for the target process.
  1196.  *    @mode contains the PTRACE_MODE flags indicating the form of access.
  1197.  *    Return 0 if permission is granted.
  1198.  * @ptrace_traceme:
  1199.  *    Check that the @parent process has sufficient permission to trace the
  1200.  *    current process before allowing the current process to present itself
  1201.  *    to the @parent process for tracing.
  1202.  *    The parent process will still have to undergo the ptrace_may_access
  1203.  *    checks before it is allowed to trace this one.
  1204.  *    @parent contains the task_struct structure for debugger process.
  1205.  *    Return 0 if permission is granted.
  1206.  * @capget:
  1207.  *    Get the @effective, @inheritable, and @permitted capability sets for
  1208.  *    the @target process.  The hook may also perform permission checking to
  1209.  *    determine if the current process is allowed to see the capability sets
  1210.  *    of the @target process.
  1211.  *    @target contains the task_struct structure for target process.
  1212.  *    @effective contains the effective capability set.
  1213.  *    @inheritable contains the inheritable capability set.
  1214.  *    @permitted contains the permitted capability set.
  1215.  *    Return 0 if the capability sets were successfully obtained.
  1216.  * @capset_check:
  1217.  *    Check permission before setting the @effective, @inheritable, and
  1218.  *    @permitted capability sets for the @target process.
  1219.  *    Caveat:  @target is also set to current if a set of processes is
  1220.  *    specified (i.e. all processes other than current and init or a
  1221.  *    particular process group).  Hence, the capset_set hook may need to
  1222.  *    revalidate permission to the actual target process.
  1223.  *    @target contains the task_struct structure for target process.
  1224.  *    @effective contains the effective capability set.
  1225.  *    @inheritable contains the inheritable capability set.
  1226.  *    @permitted contains the permitted capability set.
  1227.  *    Return 0 if permission is granted.
  1228.  * @capset_set:
  1229.  *    Set the @effective, @inheritable, and @permitted capability sets for
  1230.  *    the @target process.  Since capset_check cannot always check permission
  1231.  *    to the real @target process, this hook may also perform permission
  1232.  *    checking to determine if the current process is allowed to set the
  1233.  *    capability sets of the @target process.  However, this hook has no way
  1234.  *    of returning an error due to the structure of the sys_capset code.
  1235.  *    @target contains the task_struct structure for target process.
  1236.  *    @effective contains the effective capability set.
  1237.  *    @inheritable contains the inheritable capability set.
  1238.  *    @permitted contains the permitted capability set.
  1239.  * @capable:
  1240.  *    Check whether the @tsk process has the @cap capability.
  1241.  *    @tsk contains the task_struct for the process.
  1242.  *    @cap contains the capability <include/linux/capability.h>.
  1243.  *    Return 0 if the capability is granted for @tsk.
  1244.  * @acct:
  1245.  *    Check permission before enabling or disabling process accounting.  If
  1246.  *    accounting is being enabled, then @file refers to the open file used to
  1247.  *    store accounting records.  If accounting is being disabled, then @file
  1248.  *    is NULL.
  1249.  *    @file contains the file structure for the accounting file (may be NULL).
  1250.  *    Return 0 if permission is granted.
  1251.  * @sysctl:
  1252.  *    Check permission before accessing the @table sysctl variable in the
  1253.  *    manner specified by @op.
  1254.  *    @table contains the ctl_table structure for the sysctl variable.
  1255.  *    @op contains the operation (001 = search, 002 = write, 004 = read).
  1256.  *    Return 0 if permission is granted.
  1257.  * @syslog:
  1258.  *    Check permission before accessing the kernel message ring or changing
  1259.  *    logging to the console.
  1260.  *    See the syslog(2) manual page for an explanation of the @type values.
  1261.  *    @type contains the type of action.
  1262.  *    Return 0 if permission is granted.
  1263.  * @settime:
  1264.  *    Check permission to change the system time.
  1265.  *    struct timespec and timezone are defined in include/linux/time.h
  1266.  *    @ts contains new time
  1267.  *    @tz contains new timezone
  1268.  *    Return 0 if permission is granted.
  1269.  * @vm_enough_memory:
  1270.  *    Check permissions for allocating a new virtual mapping.
  1271.  *    @mm contains the mm struct it is being added to.
  1272.  *    @pages contains the number of pages.
  1273.  *    Return 0 if permission is granted.
  1274.  *
  1275.  * @secid_to_secctx:
  1276.  *    Convert secid to security context.
  1277.  *    @secid contains the security ID.
  1278.  *    @secdata contains the pointer that stores the converted security context.
  1279.  * @secctx_to_secid:
  1280.  *    Convert security context to secid.
  1281.  *    @secid contains the pointer to the generated security ID.
  1282.  *    @secdata contains the security context.
  1283.  *
  1284.  * @release_secctx:
  1285.  *    Release the security context.
  1286.  *    @secdata contains the security context.
  1287.  *    @seclen contains the length of the security context.
  1288.  *
  1289.  * Security hooks for Audit
  1290.  *
  1291.  * @audit_rule_init:
  1292.  *    Allocate and initialize an LSM audit rule structure.
  1293.  *    @field contains the required Audit action. Fields flags are defined in include/linux/audit.h
  1294.  *    @op contains the operator the rule uses.
  1295.  *    @rulestr contains the context where the rule will be applied to.
  1296.  *    @lsmrule contains a pointer to receive the result.
  1297.  *    Return 0 if @lsmrule has been successfully set,
  1298.  *    -EINVAL in case of an invalid rule.
  1299.  *
  1300.  * @audit_rule_known:
  1301.  *    Specifies whether given @rule contains any fields related to current LSM.
  1302.  *    @rule contains the audit rule of interest.
  1303.  *    Return 1 in case of relation found, 0 otherwise.
  1304.  *
  1305.  * @audit_rule_match:
  1306.  *    Determine if given @secid matches a rule previously approved
  1307.  *    by @audit_rule_known.
  1308.  *    @secid contains the security id in question.
  1309.  *    @field contains the field which relates to current LSM.
  1310.  *    @op contains the operator that will be used for matching.
  1311.  *    @rule points to the audit rule that will be checked against.
  1312.  *    @actx points to the audit context associated with the check.
  1313.  *    Return 1 if secid matches the rule, 0 if it does not, -ERRNO on failure.
  1314.  *
  1315.  * @audit_rule_free:
  1316.  *    Deallocate the LSM audit rule structure previously allocated by
  1317.  *    audit_rule_init.
  1318.  *    @rule contains the allocated rule
  1319.  *
  1320.  * This is the main security structure.
  1321.  */
  1322. struct security_operations {
  1323.     char name[SECURITY_NAME_MAX + 1];
  1324.  
  1325.     int (*ptrace_may_access) (struct task_struct *child, unsigned int mode);
  1326.     int (*ptrace_traceme) (struct task_struct *parent);
  1327.     int (*capget) (struct task_struct *target,
  1328.                kernel_cap_t *effective,
  1329.                kernel_cap_t *inheritable, kernel_cap_t *permitted);
  1330.     int (*capset_check) (struct task_struct *target,
  1331.                  kernel_cap_t *effective,
  1332.                  kernel_cap_t *inheritable,
  1333.                  kernel_cap_t *permitted);
  1334.     void (*capset_set) (struct task_struct *target,
  1335.                 kernel_cap_t *effective,
  1336.                 kernel_cap_t *inheritable,
  1337.                 kernel_cap_t *permitted);
  1338.     int (*capable) (struct task_struct *tsk, int cap);
  1339.     int (*acct) (struct file *file);
  1340.     int (*sysctl) (struct ctl_table *table, int op);
  1341.     int (*quotactl) (int cmds, int type, int id, struct super_block *sb);
  1342.     int (*quota_on) (struct dentry *dentry);
  1343.     int (*syslog) (int type);
  1344.     int (*settime) (struct timespec *ts, struct timezone *tz);
  1345.     int (*vm_enough_memory) (struct mm_struct *mm, long pages);
  1346.  
  1347.     int (*bprm_alloc_security) (struct linux_binprm *bprm);
  1348.     void (*bprm_free_security) (struct linux_binprm *bprm);
  1349.     void (*bprm_apply_creds) (struct linux_binprm *bprm, int unsafe);
  1350.     void (*bprm_post_apply_creds) (struct linux_binprm *bprm);
  1351.     int (*bprm_set_security) (struct linux_binprm *bprm);
  1352.     int (*bprm_check_security) (struct linux_binprm *bprm);
  1353.     int (*bprm_secureexec) (struct linux_binprm *bprm);
  1354.  
  1355.     int (*sb_alloc_security) (struct super_block *sb);
  1356.     void (*sb_free_security) (struct super_block *sb);
  1357.     int (*sb_copy_data) (char *orig, char *copy);
  1358.     int (*sb_kern_mount) (struct super_block *sb, void *data);
  1359.     int (*sb_show_options) (struct seq_file *m, struct super_block *sb);
  1360.     int (*sb_statfs) (struct dentry *dentry);
  1361.     int (*sb_mount) (char *dev_name, struct path *path,
  1362.              char *type, unsigned long flags, void *data);
  1363.     int (*sb_check_sb) (struct vfsmount *mnt, struct path *path);
  1364.     int (*sb_umount) (struct vfsmount *mnt, int flags);
  1365.     void (*sb_umount_close) (struct vfsmount *mnt);
  1366.     void (*sb_umount_busy) (struct vfsmount *mnt);
  1367.     void (*sb_post_remount) (struct vfsmount *mnt,
  1368.                  unsigned long flags, void *data);
  1369.     void (*sb_post_addmount) (struct vfsmount *mnt,
  1370.                   struct path *mountpoint);
  1371.     int (*sb_pivotroot) (struct path *old_path,
  1372.                  struct path *new_path);
  1373.     void (*sb_post_pivotroot) (struct path *old_path,
  1374.                    struct path *new_path);
  1375.     int (*sb_set_mnt_opts) (struct super_block *sb,
  1376.                 struct security_mnt_opts *opts);
  1377.     void (*sb_clone_mnt_opts) (const struct super_block *oldsb,
  1378.                    struct super_block *newsb);
  1379.     int (*sb_parse_opts_str) (char *options, struct security_mnt_opts *opts);
  1380.  
  1381.     int (*inode_alloc_security) (struct inode *inode);
  1382.     void (*inode_free_security) (struct inode *inode);
  1383.     int (*inode_init_security) (struct inode *inode, struct inode *dir,
  1384.                     char **name, void **value, size_t *len);
  1385.     int (*inode_create) (struct inode *dir, struct dentry *dentry,
  1386.                  struct vfsmount *mnt, int mode);
  1387.     int (*inode_link) (struct dentry *old_dentry, struct vfsmount *old_mnt,
  1388.                        struct inode *dir, struct dentry *new_dentry,
  1389.                struct vfsmount *new_mnt);
  1390.     int (*inode_unlink) (struct inode *dir, struct dentry *dentry,
  1391.                  struct vfsmount *mnt);
  1392.     int (*inode_symlink) (struct inode *dir, struct dentry *dentry,
  1393.                   struct vfsmount *mnt, const char *old_name);
  1394.     int (*inode_mkdir) (struct inode *dir, struct dentry *dentry,
  1395.                 struct vfsmount *mnt, int mode);
  1396.     int (*inode_rmdir) (struct inode *dir, struct dentry *dentry,
  1397.                 struct vfsmount *mnt);
  1398.     int (*inode_mknod) (struct inode *dir, struct dentry *dentry,
  1399.                 struct vfsmount *mnt, int mode, dev_t dev);
  1400.     int (*inode_rename) (struct inode *old_dir, struct dentry *old_dentry,
  1401.                  struct vfsmount *old_mnt,
  1402.                          struct inode *new_dir, struct dentry *new_dentry,
  1403.                  struct vfsmount *new_mnt);
  1404.     int (*inode_readlink) (struct dentry *dentry, struct vfsmount *mnt);
  1405.     int (*inode_follow_link) (struct dentry *dentry, struct nameidata *nd);
  1406.     int (*inode_permission) (struct inode *inode, int mask);
  1407.     int (*inode_setattr)    (struct dentry *dentry, struct vfsmount *,
  1408.                  struct iattr *attr);
  1409.     int (*inode_getattr) (struct vfsmount *mnt, struct dentry *dentry);
  1410.     void (*inode_delete) (struct inode *inode);
  1411.     int (*inode_setxattr) (struct dentry *dentry, struct vfsmount *mnt,
  1412.                    const char *name, const void *value, size_t size,
  1413.                    int flags, struct file *file);
  1414.     void (*inode_post_setxattr) (struct dentry *dentry,
  1415.                      struct vfsmount *mnt,
  1416.                      const char *name, const void *value,
  1417.                      size_t size, int flags);
  1418.     int (*inode_getxattr) (struct dentry *dentry, struct vfsmount *mnt,
  1419.                    const char *name, struct file *file);
  1420.     int (*inode_listxattr) (struct dentry *dentry, struct vfsmount *mnt,
  1421.                 struct file *file);
  1422.     int (*inode_removexattr) (struct dentry *dentry, struct vfsmount *mnt,
  1423.                   const char *name, struct file *file);
  1424.     int (*inode_need_killpriv) (struct dentry *dentry);
  1425.     int (*inode_killpriv) (struct dentry *dentry);
  1426.     int (*inode_getsecurity) (const struct inode *inode, const char *name, void **buffer, bool alloc);
  1427.     int (*inode_setsecurity) (struct inode *inode, const char *name, const void *value, size_t size, int flags);
  1428.     int (*inode_listsecurity) (struct inode *inode, char *buffer, size_t buffer_size);
  1429.     void (*inode_getsecid) (const struct inode *inode, u32 *secid);
  1430.  
  1431.     int (*file_permission) (struct file *file, int mask);
  1432.     int (*file_alloc_security) (struct file *file);
  1433.     void (*file_free_security) (struct file *file);
  1434.     int (*file_ioctl) (struct file *file, unsigned int cmd,
  1435.                unsigned long arg);
  1436.     int (*file_mmap) (struct file *file,
  1437.               unsigned long reqprot, unsigned long prot,
  1438.               unsigned long flags, unsigned long addr,
  1439.               unsigned long addr_only);
  1440.     int (*file_mprotect) (struct vm_area_struct *vma,
  1441.                   unsigned long reqprot,
  1442.                   unsigned long prot);
  1443.     int (*file_lock) (struct file *file, unsigned int cmd);
  1444.     int (*file_fcntl) (struct file *file, unsigned int cmd,
  1445.                unsigned long arg);
  1446.     int (*file_set_fowner) (struct file *file);
  1447.     int (*file_send_sigiotask) (struct task_struct *tsk,
  1448.                     struct fown_struct *fown, int sig);
  1449.     int (*file_receive) (struct file *file);
  1450.     int (*dentry_open) (struct file *file);
  1451.     int (*path_permission) (struct path *path, int mask);
  1452.  
  1453.     int (*task_create) (unsigned long clone_flags);
  1454.     int (*task_alloc_security) (struct task_struct *p);
  1455.     void (*task_free_security) (struct task_struct *p);
  1456.     int (*task_setuid) (uid_t id0, uid_t id1, uid_t id2, int flags);
  1457.     int (*task_post_setuid) (uid_t old_ruid /* or fsuid */ ,
  1458.                  uid_t old_euid, uid_t old_suid, int flags);
  1459.     int (*task_setgid) (gid_t id0, gid_t id1, gid_t id2, int flags);
  1460.     int (*task_setpgid) (struct task_struct *p, pid_t pgid);
  1461.     int (*task_getpgid) (struct task_struct *p);
  1462.     int (*task_getsid) (struct task_struct *p);
  1463.     void (*task_getsecid) (struct task_struct *p, u32 *secid);
  1464.     int (*task_setgroups) (struct group_info *group_info);
  1465.     int (*task_setnice) (struct task_struct *p, int nice);
  1466.     int (*task_setioprio) (struct task_struct *p, int ioprio);
  1467.     int (*task_getioprio) (struct task_struct *p);
  1468.     int (*task_setrlimit) (unsigned int resource, struct rlimit *new_rlim);
  1469.     int (*task_setscheduler) (struct task_struct *p, int policy,
  1470.                   struct sched_param *lp);
  1471.     int (*task_getscheduler) (struct task_struct *p);
  1472.     int (*task_movememory) (struct task_struct *p);
  1473.     int (*task_kill) (struct task_struct *p,
  1474.               struct siginfo *info, int sig, u32 secid);
  1475.     int (*task_wait) (struct task_struct *p);
  1476.     int (*task_prctl) (int option, unsigned long arg2,
  1477.                unsigned long arg3, unsigned long arg4,
  1478.                unsigned long arg5, long *rc_p);
  1479.     void (*task_reparent_to_init) (struct task_struct *p);
  1480.     void (*task_to_inode) (struct task_struct *p, struct inode *inode);
  1481.  
  1482.     int (*ipc_permission) (struct kern_ipc_perm *ipcp, short flag);
  1483.     void (*ipc_getsecid) (struct kern_ipc_perm *ipcp, u32 *secid);
  1484.  
  1485.     int (*msg_msg_alloc_security) (struct msg_msg *msg);
  1486.     void (*msg_msg_free_security) (struct msg_msg *msg);
  1487.  
  1488.     int (*msg_queue_alloc_security) (struct msg_queue *msq);
  1489.     void (*msg_queue_free_security) (struct msg_queue *msq);
  1490.     int (*msg_queue_associate) (struct msg_queue *msq, int msqflg);
  1491.     int (*msg_queue_msgctl) (struct msg_queue *msq, int cmd);
  1492.     int (*msg_queue_msgsnd) (struct msg_queue *msq,
  1493.                  struct msg_msg *msg, int msqflg);
  1494.     int (*msg_queue_msgrcv) (struct msg_queue *msq,
  1495.                  struct msg_msg *msg,
  1496.                  struct task_struct *target,
  1497.                  long type, int mode);
  1498.  
  1499.     int (*shm_alloc_security) (struct shmid_kernel *shp);
  1500.     void (*shm_free_security) (struct shmid_kernel *shp);
  1501.     int (*shm_associate) (struct shmid_kernel *shp, int shmflg);
  1502.     int (*shm_shmctl) (struct shmid_kernel *shp, int cmd);
  1503.     int (*shm_shmat) (struct shmid_kernel *shp,
  1504.               char __user *shmaddr, int shmflg);
  1505.  
  1506.     int (*sem_alloc_security) (struct sem_array *sma);
  1507.     void (*sem_free_security) (struct sem_array *sma);
  1508.     int (*sem_associate) (struct sem_array *sma, int semflg);
  1509.     int (*sem_semctl) (struct sem_array *sma, int cmd);
  1510.     int (*sem_semop) (struct sem_array *sma,
  1511.               struct sembuf *sops, unsigned nsops, int alter);
  1512.  
  1513.     int (*netlink_send) (struct sock *sk, struct sk_buff *skb);
  1514.     int (*netlink_recv) (struct sk_buff *skb, int cap);
  1515.  
  1516.     void (*d_instantiate) (struct dentry *dentry, struct inode *inode);
  1517.  
  1518.     int (*getprocattr) (struct task_struct *p, char *name, char **value);
  1519.     int (*setprocattr) (struct task_struct *p, char *name, void *value, size_t size);
  1520.     int (*secid_to_secctx) (u32 secid, char **secdata, u32 *seclen);
  1521.     int (*secctx_to_secid) (const char *secdata, u32 seclen, u32 *secid);
  1522.     void (*release_secctx) (char *secdata, u32 seclen);
  1523.  
  1524. #ifdef CONFIG_SECURITY_NETWORK
  1525.     int (*unix_stream_connect) (struct socket *sock,
  1526.                     struct socket *other, struct sock *newsk);
  1527.     int (*unix_may_send) (struct socket *sock, struct socket *other);
  1528.  
  1529.     int (*socket_create) (int family, int type, int protocol, int kern);
  1530.     int (*socket_post_create) (struct socket *sock, int family,
  1531.                    int type, int protocol, int kern);
  1532.     int (*socket_bind) (struct socket *sock,
  1533.                 struct sockaddr *address, int addrlen);
  1534.     int (*socket_connect) (struct socket *sock,
  1535.                    struct sockaddr *address, int addrlen);
  1536.     int (*socket_listen) (struct socket *sock, int backlog);
  1537.     int (*socket_accept) (struct socket *sock, struct socket *newsock);
  1538.     void (*socket_post_accept) (struct socket *sock,
  1539.                     struct socket *newsock);
  1540.     int (*socket_sendmsg) (struct socket *sock,
  1541.                    struct msghdr *msg, int size);
  1542.     int (*socket_recvmsg) (struct socket *sock,
  1543.                    struct msghdr *msg, int size, int flags);
  1544.     int (*socket_getsockname) (struct socket *sock);
  1545.     int (*socket_getpeername) (struct socket *sock);
  1546.     int (*socket_getsockopt) (struct socket *sock, int level, int optname);
  1547.     int (*socket_setsockopt) (struct socket *sock, int level, int optname);
  1548.     int (*socket_shutdown) (struct socket *sock, int how);
  1549.     int (*socket_sock_rcv_skb) (struct sock *sk, struct sk_buff *skb);
  1550.     int (*socket_getpeersec_stream) (struct socket *sock, char __user *optval, int __user *optlen, unsigned len);
  1551.     int (*socket_getpeersec_dgram) (struct socket *sock, struct sk_buff *skb, u32 *secid);
  1552.     int (*sk_alloc_security) (struct sock *sk, int family, gfp_t priority);
  1553.     void (*sk_free_security) (struct sock *sk);
  1554.     void (*sk_clone_security) (const struct sock *sk, struct sock *newsk);
  1555.     void (*sk_getsecid) (struct sock *sk, u32 *secid);
  1556.     void (*sock_graft) (struct sock *sk, struct socket *parent);
  1557.     int (*inet_conn_request) (struct sock *sk, struct sk_buff *skb,
  1558.                   struct request_sock *req);
  1559.     void (*inet_csk_clone) (struct sock *newsk, const struct request_sock *req);
  1560.     void (*inet_conn_established) (struct sock *sk, struct sk_buff *skb);
  1561.     void (*req_classify_flow) (const struct request_sock *req, struct flowi *fl);
  1562. #endif    /* CONFIG_SECURITY_NETWORK */
  1563.  
  1564. #ifdef CONFIG_SECURITY_NETWORK_XFRM
  1565.     int (*xfrm_policy_alloc_security) (struct xfrm_sec_ctx **ctxp,
  1566.             struct xfrm_user_sec_ctx *sec_ctx);
  1567.     int (*xfrm_policy_clone_security) (struct xfrm_sec_ctx *old_ctx, struct xfrm_sec_ctx **new_ctx);
  1568.     void (*xfrm_policy_free_security) (struct xfrm_sec_ctx *ctx);
  1569.     int (*xfrm_policy_delete_security) (struct xfrm_sec_ctx *ctx);
  1570.     int (*xfrm_state_alloc_security) (struct xfrm_state *x,
  1571.         struct xfrm_user_sec_ctx *sec_ctx,
  1572.         u32 secid);
  1573.     void (*xfrm_state_free_security) (struct xfrm_state *x);
  1574.     int (*xfrm_state_delete_security) (struct xfrm_state *x);
  1575.     int (*xfrm_policy_lookup) (struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir);
  1576.     int (*xfrm_state_pol_flow_match) (struct xfrm_state *x,
  1577.                       struct xfrm_policy *xp,
  1578.                       struct flowi *fl);
  1579.     int (*xfrm_decode_session) (struct sk_buff *skb, u32 *secid, int ckall);
  1580. #endif    /* CONFIG_SECURITY_NETWORK_XFRM */
  1581.  
  1582.     /* key management security hooks */
  1583. #ifdef CONFIG_KEYS
  1584.     int (*key_alloc) (struct key *key, struct task_struct *tsk, unsigned long flags);
  1585.     void (*key_free) (struct key *key);
  1586.     int (*key_permission) (key_ref_t key_ref,
  1587.                    struct task_struct *context,
  1588.                    key_perm_t perm);
  1589.     int (*key_getsecurity)(struct key *key, char **_buffer);
  1590. #endif    /* CONFIG_KEYS */
  1591.  
  1592. #ifdef CONFIG_AUDIT
  1593.     int (*audit_rule_init) (u32 field, u32 op, char *rulestr, void **lsmrule);
  1594.     int (*audit_rule_known) (struct audit_krule *krule);
  1595.     int (*audit_rule_match) (u32 secid, u32 field, u32 op, void *lsmrule,
  1596.                  struct audit_context *actx);
  1597.     void (*audit_rule_free) (void *lsmrule);
  1598. #endif /* CONFIG_AUDIT */
  1599. };
  1600.  
  1601. /* prototypes */
  1602. extern int security_init(void);
  1603. extern int security_module_enable(struct security_operations *ops);
  1604. extern int register_security(struct security_operations *ops);
  1605.  
  1606. /* Security operations */
  1607. int security_ptrace_may_access(struct task_struct *child, unsigned int mode);
  1608. int security_ptrace_traceme(struct task_struct *parent);
  1609. int security_capget(struct task_struct *target,
  1610.             kernel_cap_t *effective,
  1611.             kernel_cap_t *inheritable,
  1612.             kernel_cap_t *permitted);
  1613. int security_capset_check(struct task_struct *target,
  1614.               kernel_cap_t *effective,
  1615.               kernel_cap_t *inheritable,
  1616.               kernel_cap_t *permitted);
  1617. void security_capset_set(struct task_struct *target,
  1618.              kernel_cap_t *effective,
  1619.              kernel_cap_t *inheritable,
  1620.              kernel_cap_t *permitted);
  1621. int security_capable(struct task_struct *tsk, int cap);
  1622. int security_acct(struct file *file);
  1623. int security_sysctl(struct ctl_table *table, int op);
  1624. int security_quotactl(int cmds, int type, int id, struct super_block *sb);
  1625. int security_quota_on(struct dentry *dentry);
  1626. int security_syslog(int type);
  1627. int security_settime(struct timespec *ts, struct timezone *tz);
  1628. int security_vm_enough_memory(long pages);
  1629. int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
  1630. int security_vm_enough_memory_kern(long pages);
  1631. int security_bprm_alloc(struct linux_binprm *bprm);
  1632. void security_bprm_free(struct linux_binprm *bprm);
  1633. void security_bprm_apply_creds(struct linux_binprm *bprm, int unsafe);
  1634. void security_bprm_post_apply_creds(struct linux_binprm *bprm);
  1635. int security_bprm_set(struct linux_binprm *bprm);
  1636. int security_bprm_check(struct linux_binprm *bprm);
  1637. int security_bprm_secureexec(struct linux_binprm *bprm);
  1638. int security_sb_alloc(struct super_block *sb);
  1639. void security_sb_free(struct super_block *sb);
  1640. int security_sb_copy_data(char *orig, char *copy);
  1641. int security_sb_kern_mount(struct super_block *sb, void *data);
  1642. int security_sb_show_options(struct seq_file *m, struct super_block *sb);
  1643. int security_sb_statfs(struct dentry *dentry);
  1644. int security_sb_mount(char *dev_name, struct path *path,
  1645.               char *type, unsigned long flags, void *data);
  1646. int security_sb_check_sb(struct vfsmount *mnt, struct path *path);
  1647. int security_sb_umount(struct vfsmount *mnt, int flags);
  1648. void security_sb_umount_close(struct vfsmount *mnt);
  1649. void security_sb_umount_busy(struct vfsmount *mnt);
  1650. void security_sb_post_remount(struct vfsmount *mnt, unsigned long flags, void *data);
  1651. void security_sb_post_addmount(struct vfsmount *mnt, struct path *mountpoint);
  1652. int security_sb_pivotroot(struct path *old_path, struct path *new_path);
  1653. void security_sb_post_pivotroot(struct path *old_path, struct path *new_path);
  1654. int security_sb_set_mnt_opts(struct super_block *sb, struct security_mnt_opts *opts);
  1655. void security_sb_clone_mnt_opts(const struct super_block *oldsb,
  1656.                 struct super_block *newsb);
  1657. int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts);
  1658.  
  1659. int security_inode_alloc(struct inode *inode);
  1660. void security_inode_free(struct inode *inode);
  1661. int security_inode_init_security(struct inode *inode, struct inode *dir,
  1662.                   char **name, void **value, size_t *len);
  1663. int security_inode_create(struct inode *dir, struct dentry *dentry,
  1664.               struct vfsmount *mnt, int mode);
  1665. int security_inode_link(struct dentry *old_dentry, struct vfsmount *old_mnt,
  1666.             struct inode *dir, struct dentry *new_dentry,
  1667.             struct vfsmount *new_mnt);
  1668. int security_inode_unlink(struct inode *dir, struct dentry *dentry,
  1669.               struct vfsmount *mnt);
  1670. int security_inode_symlink(struct inode *dir, struct dentry *dentry,
  1671.                struct vfsmount *mnt, const char *old_name);
  1672. int security_inode_mkdir(struct inode *dir, struct dentry *dentry,
  1673.              struct vfsmount *mnt, int mode);
  1674. int security_inode_rmdir(struct inode *dir, struct dentry *dentry,
  1675.              struct vfsmount *mnt);
  1676. int security_inode_mknod(struct inode *dir, struct dentry *dentry,
  1677.              struct vfsmount *mnt, int mode, dev_t dev);
  1678. int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
  1679.               struct vfsmount *old_mnt, struct inode *new_dir,
  1680.               struct dentry *new_dentry, struct vfsmount *new_mnt);
  1681. int security_inode_readlink(struct dentry *dentry, struct vfsmount *mnt);
  1682. int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd);
  1683. int security_inode_permission(struct inode *inode, int mask);
  1684. int security_inode_setattr(struct dentry *dentry, struct vfsmount *mnt,
  1685.                struct iattr *attr);
  1686. int security_inode_getattr(struct vfsmount *mnt, struct dentry *dentry);
  1687. void security_inode_delete(struct inode *inode);
  1688. int security_inode_setxattr(struct dentry *dentry, struct vfsmount *mnt,
  1689.                 const char *name, const void *value,
  1690.                 size_t size, int flags, struct file *file);
  1691. void security_inode_post_setxattr(struct dentry *dentry, struct vfsmount *mnt,
  1692.                   const char *name, const void *value,
  1693.                   size_t size, int flags);
  1694. int security_inode_getxattr(struct dentry *dentry, struct vfsmount *mnt,
  1695.                 const char *name, struct file *file);
  1696. int security_inode_listxattr(struct dentry *dentry, struct vfsmount *mnt,
  1697.                  struct file *file);
  1698. int security_inode_removexattr(struct dentry *dentry, struct vfsmount *mnt,
  1699.                    const char *name, struct file *file);
  1700. int security_inode_need_killpriv(struct dentry *dentry);
  1701. int security_inode_killpriv(struct dentry *dentry);
  1702. int security_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc);
  1703. int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags);
  1704. int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size);
  1705. void security_inode_getsecid(const struct inode *inode, u32 *secid);
  1706. int security_file_permission(struct file *file, int mask);
  1707. int security_file_alloc(struct file *file);
  1708. void security_file_free(struct file *file);
  1709. int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  1710. int security_file_mmap(struct file *file, unsigned long reqprot,
  1711.             unsigned long prot, unsigned long flags,
  1712.             unsigned long addr, unsigned long addr_only);
  1713. int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
  1714.                unsigned long prot);
  1715. int security_file_lock(struct file *file, unsigned int cmd);
  1716. int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg);
  1717. int security_file_set_fowner(struct file *file);
  1718. int security_file_send_sigiotask(struct task_struct *tsk,
  1719.                  struct fown_struct *fown, int sig);
  1720. int security_file_receive(struct file *file);
  1721. int security_dentry_open(struct file *file);
  1722. int security_path_permission(struct path *path, int mask);
  1723. int security_task_create(unsigned long clone_flags);
  1724. int security_task_alloc(struct task_struct *p);
  1725. void security_task_free(struct task_struct *p);
  1726. int security_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags);
  1727. int security_task_post_setuid(uid_t old_ruid, uid_t old_euid,
  1728.                   uid_t old_suid, int flags);
  1729. int security_task_setgid(gid_t id0, gid_t id1, gid_t id2, int flags);
  1730. int security_task_setpgid(struct task_struct *p, pid_t pgid);
  1731. int security_task_getpgid(struct task_struct *p);
  1732. int security_task_getsid(struct task_struct *p);
  1733. void security_task_getsecid(struct task_struct *p, u32 *secid);
  1734. int security_task_setgroups(struct group_info *group_info);
  1735. int security_task_setnice(struct task_struct *p, int nice);
  1736. int security_task_setioprio(struct task_struct *p, int ioprio);
  1737. int security_task_getioprio(struct task_struct *p);
  1738. int security_task_setrlimit(unsigned int resource, struct rlimit *new_rlim);
  1739. int security_task_setscheduler(struct task_struct *p,
  1740.                 int policy, struct sched_param *lp);
  1741. int security_task_getscheduler(struct task_struct *p);
  1742. int security_task_movememory(struct task_struct *p);
  1743. int security_task_kill(struct task_struct *p, struct siginfo *info,
  1744.             int sig, u32 secid);
  1745. int security_task_wait(struct task_struct *p);
  1746. int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
  1747.              unsigned long arg4, unsigned long arg5, long *rc_p);
  1748. void security_task_reparent_to_init(struct task_struct *p);
  1749. void security_task_to_inode(struct task_struct *p, struct inode *inode);
  1750. int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag);
  1751. void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid);
  1752. int security_msg_msg_alloc(struct msg_msg *msg);
  1753. void security_msg_msg_free(struct msg_msg *msg);
  1754. int security_msg_queue_alloc(struct msg_queue *msq);
  1755. void security_msg_queue_free(struct msg_queue *msq);
  1756. int security_msg_queue_associate(struct msg_queue *msq, int msqflg);
  1757. int security_msg_queue_msgctl(struct msg_queue *msq, int cmd);
  1758. int security_msg_queue_msgsnd(struct msg_queue *msq,
  1759.                   struct msg_msg *msg, int msqflg);
  1760. int security_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
  1761.                   struct task_struct *target, long type, int mode);
  1762. int security_shm_alloc(struct shmid_kernel *shp);
  1763. void security_shm_free(struct shmid_kernel *shp);
  1764. int security_shm_associate(struct shmid_kernel *shp, int shmflg);
  1765. int security_shm_shmctl(struct shmid_kernel *shp, int cmd);
  1766. int security_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr, int shmflg);
  1767. int security_sem_alloc(struct sem_array *sma);
  1768. void security_sem_free(struct sem_array *sma);
  1769. int security_sem_associate(struct sem_array *sma, int semflg);
  1770. int security_sem_semctl(struct sem_array *sma, int cmd);
  1771. int security_sem_semop(struct sem_array *sma, struct sembuf *sops,
  1772.             unsigned nsops, int alter);
  1773. void security_d_instantiate(struct dentry *dentry, struct inode *inode);
  1774. int security_getprocattr(struct task_struct *p, char *name, char **value);
  1775. int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size);
  1776. int security_netlink_send(struct sock *sk, struct sk_buff *skb);
  1777. int security_netlink_recv(struct sk_buff *skb, int cap);
  1778. int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen);
  1779. int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid);
  1780. void security_release_secctx(char *secdata, u32 seclen);
  1781.  
  1782. #else /* CONFIG_SECURITY */
  1783. struct security_mnt_opts {
  1784. };
  1785.  
  1786. static inline void security_init_mnt_opts(struct security_mnt_opts *opts)
  1787. {
  1788. }
  1789.  
  1790. static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  1791. {
  1792. }
  1793.  
  1794. /*
  1795.  * This is the default capabilities functionality.  Most of these functions
  1796.  * are just stubbed out, but a few must call the proper capable code.
  1797.  */
  1798.  
  1799. static inline int security_init(void)
  1800. {
  1801.     return 0;
  1802. }
  1803.  
  1804. static inline int security_ptrace_may_access(struct task_struct *child,
  1805.                          unsigned int mode)
  1806. {
  1807.     return cap_ptrace_may_access(child, mode);
  1808. }
  1809.  
  1810. static inline int security_ptrace_traceme(struct task_struct *parent)
  1811. {
  1812.     return cap_ptrace_traceme(parent);
  1813. }
  1814.  
  1815. static inline int security_capget(struct task_struct *target,
  1816.                    kernel_cap_t *effective,
  1817.                    kernel_cap_t *inheritable,
  1818.                    kernel_cap_t *permitted)
  1819. {
  1820.     return cap_capget(target, effective, inheritable, permitted);
  1821. }
  1822.  
  1823. static inline int security_capset_check(struct task_struct *target,
  1824.                      kernel_cap_t *effective,
  1825.                      kernel_cap_t *inheritable,
  1826.                      kernel_cap_t *permitted)
  1827. {
  1828.     return cap_capset_check(target, effective, inheritable, permitted);
  1829. }
  1830.  
  1831. static inline void security_capset_set(struct task_struct *target,
  1832.                     kernel_cap_t *effective,
  1833.                     kernel_cap_t *inheritable,
  1834.                     kernel_cap_t *permitted)
  1835. {
  1836.     cap_capset_set(target, effective, inheritable, permitted);
  1837. }
  1838.  
  1839. static inline int security_capable(struct task_struct *tsk, int cap)
  1840. {
  1841.     return cap_capable(tsk, cap);
  1842. }
  1843.  
  1844. static inline int security_acct(struct file *file)
  1845. {
  1846.     return 0;
  1847. }
  1848.  
  1849. static inline int security_sysctl(struct ctl_table *table, int op)
  1850. {
  1851.     return 0;
  1852. }
  1853.  
  1854. static inline int security_quotactl(int cmds, int type, int id,
  1855.                      struct super_block *sb)
  1856. {
  1857.     return 0;
  1858. }
  1859.  
  1860. static inline int security_quota_on(struct dentry *dentry)
  1861. {
  1862.     return 0;
  1863. }
  1864.  
  1865. static inline int security_syslog(int type)
  1866. {
  1867.     return cap_syslog(type);
  1868. }
  1869.  
  1870. static inline int security_settime(struct timespec *ts, struct timezone *tz)
  1871. {
  1872.     return cap_settime(ts, tz);
  1873. }
  1874.  
  1875. static inline int security_vm_enough_memory(long pages)
  1876. {
  1877.     WARN_ON(current->mm == NULL);
  1878.     return cap_vm_enough_memory(current->mm, pages);
  1879. }
  1880.  
  1881. static inline int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
  1882. {
  1883.     WARN_ON(mm == NULL);
  1884.     return cap_vm_enough_memory(mm, pages);
  1885. }
  1886.  
  1887. static inline int security_vm_enough_memory_kern(long pages)
  1888. {
  1889.     /* If current->mm is a kernel thread then we will pass NULL,
  1890.        for this specific case that is fine */
  1891.     return cap_vm_enough_memory(current->mm, pages);
  1892. }
  1893.  
  1894. static inline int security_bprm_alloc(struct linux_binprm *bprm)
  1895. {
  1896.     return 0;
  1897. }
  1898.  
  1899. static inline void security_bprm_free(struct linux_binprm *bprm)
  1900. { }
  1901.  
  1902. static inline void security_bprm_apply_creds(struct linux_binprm *bprm, int unsafe)
  1903. {
  1904.     cap_bprm_apply_creds(bprm, unsafe);
  1905. }
  1906.  
  1907. static inline void security_bprm_post_apply_creds(struct linux_binprm *bprm)
  1908. {
  1909.     return;
  1910. }
  1911.  
  1912. static inline int security_bprm_set(struct linux_binprm *bprm)
  1913. {
  1914.     return cap_bprm_set_security(bprm);
  1915. }
  1916.  
  1917. static inline int security_bprm_check(struct linux_binprm *bprm)
  1918. {
  1919.     return 0;
  1920. }
  1921.  
  1922. static inline int security_bprm_secureexec(struct linux_binprm *bprm)
  1923. {
  1924.     return cap_bprm_secureexec(bprm);
  1925. }
  1926.  
  1927. static inline int security_sb_alloc(struct super_block *sb)
  1928. {
  1929.     return 0;
  1930. }
  1931.  
  1932. static inline void security_sb_free(struct super_block *sb)
  1933. { }
  1934.  
  1935. static inline int security_sb_copy_data(char *orig, char *copy)
  1936. {
  1937.     return 0;
  1938. }
  1939.  
  1940. static inline int security_sb_kern_mount(struct super_block *sb, void *data)
  1941. {
  1942.     return 0;
  1943. }
  1944.  
  1945. static inline int security_sb_show_options(struct seq_file *m,
  1946.                        struct super_block *sb)
  1947. {
  1948.     return 0;
  1949. }
  1950.  
  1951. static inline int security_sb_statfs(struct dentry *dentry)
  1952. {
  1953.     return 0;
  1954. }
  1955.  
  1956. static inline int security_sb_mount(char *dev_name, struct path *path,
  1957.                     char *type, unsigned long flags,
  1958.                     void *data)
  1959. {
  1960.     return 0;
  1961. }
  1962.  
  1963. static inline int security_sb_check_sb(struct vfsmount *mnt,
  1964.                        struct path *path)
  1965. {
  1966.     return 0;
  1967. }
  1968.  
  1969. static inline int security_sb_umount(struct vfsmount *mnt, int flags)
  1970. {
  1971.     return 0;
  1972. }
  1973.  
  1974. static inline void security_sb_umount_close(struct vfsmount *mnt)
  1975. { }
  1976.  
  1977. static inline void security_sb_umount_busy(struct vfsmount *mnt)
  1978. { }
  1979.  
  1980. static inline void security_sb_post_remount(struct vfsmount *mnt,
  1981.                          unsigned long flags, void *data)
  1982. { }
  1983.  
  1984. static inline void security_sb_post_addmount(struct vfsmount *mnt,
  1985.                          struct path *mountpoint)
  1986. { }
  1987.  
  1988. static inline int security_sb_pivotroot(struct path *old_path,
  1989.                     struct path *new_path)
  1990. {
  1991.     return 0;
  1992. }
  1993.  
  1994. static inline void security_sb_post_pivotroot(struct path *old_path,
  1995.                           struct path *new_path)
  1996. { }
  1997.  
  1998. static inline int security_sb_set_mnt_opts(struct super_block *sb,
  1999.                        struct security_mnt_opts *opts)
  2000. {
  2001.     return 0;
  2002. }
  2003.  
  2004. static inline void security_sb_clone_mnt_opts(const struct super_block *oldsb,
  2005.                           struct super_block *newsb)
  2006. { }
  2007.  
  2008. static inline int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts)
  2009. {
  2010.     return 0;
  2011. }
  2012.  
  2013. static inline int security_inode_alloc(struct inode *inode)
  2014. {
  2015.     return 0;
  2016. }
  2017.  
  2018. static inline void security_inode_free(struct inode *inode)
  2019. { }
  2020.  
  2021. static inline int security_inode_init_security(struct inode *inode,
  2022.                         struct inode *dir,
  2023.                         char **name,
  2024.                         void **value,
  2025.                         size_t *len)
  2026. {
  2027.     return -EOPNOTSUPP;
  2028. }
  2029.  
  2030. static inline int security_inode_create(struct inode *dir,
  2031.                      struct dentry *dentry,
  2032.                      struct vfsmount *mnt,
  2033.                      int mode)
  2034. {
  2035.     return 0;
  2036. }
  2037.  
  2038. static inline int security_inode_link(struct dentry *old_dentry,
  2039.                       struct vfsmount *old_mnt,
  2040.                       struct inode *dir,
  2041.                       struct dentry *new_dentry,
  2042.                       struct vfsmount *new_mnt)
  2043. {
  2044.     return 0;
  2045. }
  2046.  
  2047. static inline int security_inode_unlink(struct inode *dir,
  2048.                     struct dentry *dentry,
  2049.                     struct vfsmount *mnt)
  2050. {
  2051.     return 0;
  2052. }
  2053.  
  2054. static inline int security_inode_symlink(struct inode *dir,
  2055.                       struct dentry *dentry,
  2056.                       struct vfsmount *mnt,
  2057.                       const char *old_name)
  2058. {
  2059.     return 0;
  2060. }
  2061.  
  2062. static inline int security_inode_mkdir(struct inode *dir,
  2063.                     struct dentry *dentry,
  2064.                     struct vfsmount *mnt,
  2065.                     int mode)
  2066. {
  2067.     return 0;
  2068. }
  2069.  
  2070. static inline int security_inode_rmdir(struct inode *dir,
  2071.                        struct dentry *dentry,
  2072.                        struct vfsmount *mnt)
  2073. {
  2074.     return 0;
  2075. }
  2076.  
  2077. static inline int security_inode_mknod(struct inode *dir,
  2078.                     struct dentry *dentry,
  2079.                     struct vfsmount *mnt,
  2080.                     int mode, dev_t dev)
  2081. {
  2082.     return 0;
  2083. }
  2084.  
  2085. static inline int security_inode_rename(struct inode *old_dir,
  2086.                      struct dentry *old_dentry,
  2087.                      struct vfsmount *old_mnt,
  2088.                      struct inode *new_dir,
  2089.                      struct dentry *new_dentry,
  2090.                      struct vfsmount *new_mnt)
  2091. {
  2092.     return 0;
  2093. }
  2094.  
  2095. static inline int security_inode_readlink(struct dentry *dentry,
  2096.                       struct vfsmount *mnt)
  2097. {
  2098.     return 0;
  2099. }
  2100.  
  2101. static inline int security_inode_follow_link(struct dentry *dentry,
  2102.                           struct nameidata *nd)
  2103. {
  2104.     return 0;
  2105. }
  2106.  
  2107. static inline int security_inode_permission(struct inode *inode, int mask)
  2108. {
  2109.     return 0;
  2110. }
  2111.  
  2112. static inline int security_inode_setattr(struct dentry *dentry,
  2113.                      struct vfsmount *mnt,
  2114.                      struct iattr *attr)
  2115. {
  2116.     return 0;
  2117. }
  2118.  
  2119. static inline int security_inode_getattr(struct vfsmount *mnt,
  2120.                       struct dentry *dentry)
  2121. {
  2122.     return 0;
  2123. }
  2124.  
  2125. static inline void security_inode_delete(struct inode *inode)
  2126. { }
  2127.  
  2128. static inline int security_inode_setxattr(struct dentry *dentry,
  2129.                       struct vfsmount *mnt,
  2130.                       const char *name, const void *value,
  2131.                       size_t size, int flags,
  2132.                       struct file *file)
  2133. {
  2134.     return cap_inode_setxattr(dentry, mnt, name, value, size, flags, file);
  2135. }
  2136.  
  2137. static inline void security_inode_post_setxattr(struct dentry *dentry,
  2138.                         struct vfsmount *mnt,
  2139.                         const char *name,
  2140.                         const void *value,
  2141.                         size_t size, int flags)
  2142. { }
  2143.  
  2144. static inline int security_inode_getxattr(struct dentry *dentry,
  2145.                       struct vfsmount *mnt,
  2146.                       const char *name,
  2147.                       struct file *file)
  2148. {
  2149.     return 0;
  2150. }
  2151.  
  2152. static inline int security_inode_listxattr(struct dentry *dentry,
  2153.                        struct vfsmount *mnt,
  2154.                        struct file *file)
  2155. {
  2156.     return 0;
  2157. }
  2158.  
  2159. static inline int security_inode_removexattr(struct dentry *dentry,
  2160.                          struct vfsmount *mnt,
  2161.                          const char *name,
  2162.                          struct file *file)
  2163. {
  2164.     return cap_inode_removexattr(dentry, mnt, name, file);
  2165. }
  2166.  
  2167. static inline int security_inode_need_killpriv(struct dentry *dentry)
  2168. {
  2169.     return cap_inode_need_killpriv(dentry);
  2170. }
  2171.  
  2172. static inline int security_inode_killpriv(struct dentry *dentry)
  2173. {
  2174.     return cap_inode_killpriv(dentry);
  2175. }
  2176.  
  2177. static inline int security_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc)
  2178. {
  2179.     return -EOPNOTSUPP;
  2180. }
  2181.  
  2182. static inline int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
  2183. {
  2184.     return -EOPNOTSUPP;
  2185. }
  2186.  
  2187. static inline int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
  2188. {
  2189.     return 0;
  2190. }
  2191.  
  2192. static inline void security_inode_getsecid(const struct inode *inode, u32 *secid)
  2193. {
  2194.     *secid = 0;
  2195. }
  2196.  
  2197. static inline int security_file_permission(struct file *file, int mask)
  2198. {
  2199.     return 0;
  2200. }
  2201.  
  2202. static inline int security_file_alloc(struct file *file)
  2203. {
  2204.     return 0;
  2205. }
  2206.  
  2207. static inline void security_file_free(struct file *file)
  2208. { }
  2209.  
  2210. static inline int security_file_ioctl(struct file *file, unsigned int cmd,
  2211.                       unsigned long arg)
  2212. {
  2213.     return 0;
  2214. }
  2215.  
  2216. static inline int security_file_mmap(struct file *file, unsigned long reqprot,
  2217.                      unsigned long prot,
  2218.                      unsigned long flags,
  2219.                      unsigned long addr,
  2220.                      unsigned long addr_only)
  2221. {
  2222.     return 0;
  2223. }
  2224.  
  2225. static inline int security_file_mprotect(struct vm_area_struct *vma,
  2226.                      unsigned long reqprot,
  2227.                      unsigned long prot)
  2228. {
  2229.     return 0;
  2230. }
  2231.  
  2232. static inline int security_file_lock(struct file *file, unsigned int cmd)
  2233. {
  2234.     return 0;
  2235. }
  2236.  
  2237. static inline int security_file_fcntl(struct file *file, unsigned int cmd,
  2238.                       unsigned long arg)
  2239. {
  2240.     return 0;
  2241. }
  2242.  
  2243. static inline int security_file_set_fowner(struct file *file)
  2244. {
  2245.     return 0;
  2246. }
  2247.  
  2248. static inline int security_file_send_sigiotask(struct task_struct *tsk,
  2249.                            struct fown_struct *fown,
  2250.                            int sig)
  2251. {
  2252.     return 0;
  2253. }
  2254.  
  2255. static inline int security_file_receive(struct file *file)
  2256. {
  2257.     return 0;
  2258. }
  2259.  
  2260. static inline int security_dentry_open(struct file *file)
  2261. {
  2262.     return 0;
  2263. }
  2264.  
  2265. static inline int security_path_permission(struct path *path, int mask)
  2266. {
  2267.     return 0;
  2268. }
  2269.  
  2270. static inline int security_task_create(unsigned long clone_flags)
  2271. {
  2272.     return 0;
  2273. }
  2274.  
  2275. static inline int security_task_alloc(struct task_struct *p)
  2276. {
  2277.     return 0;
  2278. }
  2279.  
  2280. static inline void security_task_free(struct task_struct *p)
  2281. { }
  2282.  
  2283. static inline int security_task_setuid(uid_t id0, uid_t id1, uid_t id2,
  2284.                        int flags)
  2285. {
  2286.     return 0;
  2287. }
  2288.  
  2289. static inline int security_task_post_setuid(uid_t old_ruid, uid_t old_euid,
  2290.                         uid_t old_suid, int flags)
  2291. {
  2292.     return cap_task_post_setuid(old_ruid, old_euid, old_suid, flags);
  2293. }
  2294.  
  2295. static inline int security_task_setgid(gid_t id0, gid_t id1, gid_t id2,
  2296.                        int flags)
  2297. {
  2298.     return 0;
  2299. }
  2300.  
  2301. static inline int security_task_setpgid(struct task_struct *p, pid_t pgid)
  2302. {
  2303.     return 0;
  2304. }
  2305.  
  2306. static inline int security_task_getpgid(struct task_struct *p)
  2307. {
  2308.     return 0;
  2309. }
  2310.  
  2311. static inline int security_task_getsid(struct task_struct *p)
  2312. {
  2313.     return 0;
  2314. }
  2315.  
  2316. static inline void security_task_getsecid(struct task_struct *p, u32 *secid)
  2317. {
  2318.     *secid = 0;
  2319. }
  2320.  
  2321. static inline int security_task_setgroups(struct group_info *group_info)
  2322. {
  2323.     return 0;
  2324. }
  2325.  
  2326. static inline int security_task_setnice(struct task_struct *p, int nice)
  2327. {
  2328.     return cap_task_setnice(p, nice);
  2329. }
  2330.  
  2331. static inline int security_task_setioprio(struct task_struct *p, int ioprio)
  2332. {
  2333.     return cap_task_setioprio(p, ioprio);
  2334. }
  2335.  
  2336. static inline int security_task_getioprio(struct task_struct *p)
  2337. {
  2338.     return 0;
  2339. }
  2340.  
  2341. static inline int security_task_setrlimit(unsigned int resource,
  2342.                       struct rlimit *new_rlim)
  2343. {
  2344.     return 0;
  2345. }
  2346.  
  2347. static inline int security_task_setscheduler(struct task_struct *p,
  2348.                          int policy,
  2349.                          struct sched_param *lp)
  2350. {
  2351.     return cap_task_setscheduler(p, policy, lp);
  2352. }
  2353.  
  2354. static inline int security_task_getscheduler(struct task_struct *p)
  2355. {
  2356.     return 0;
  2357. }
  2358.  
  2359. static inline int security_task_movememory(struct task_struct *p)
  2360. {
  2361.     return 0;
  2362. }
  2363.  
  2364. static inline int security_task_kill(struct task_struct *p,
  2365.                      struct siginfo *info, int sig,
  2366.                      u32 secid)
  2367. {
  2368.     return 0;
  2369. }
  2370.  
  2371. static inline int security_task_wait(struct task_struct *p)
  2372. {
  2373.     return 0;
  2374. }
  2375.  
  2376. static inline int security_task_prctl(int option, unsigned long arg2,
  2377.                       unsigned long arg3,
  2378.                       unsigned long arg4,
  2379.                       unsigned long arg5, long *rc_p)
  2380. {
  2381.     return cap_task_prctl(option, arg2, arg3, arg3, arg5, rc_p);
  2382. }
  2383.  
  2384. static inline void security_task_reparent_to_init(struct task_struct *p)
  2385. {
  2386.     cap_task_reparent_to_init(p);
  2387. }
  2388.  
  2389. static inline void security_task_to_inode(struct task_struct *p, struct inode *inode)
  2390. { }
  2391.  
  2392. static inline int security_ipc_permission(struct kern_ipc_perm *ipcp,
  2393.                       short flag)
  2394. {
  2395.     return 0;
  2396. }
  2397.  
  2398. static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
  2399. {
  2400.     *secid = 0;
  2401. }
  2402.  
  2403. static inline int security_msg_msg_alloc(struct msg_msg *msg)
  2404. {
  2405.     return 0;
  2406. }
  2407.  
  2408. static inline void security_msg_msg_free(struct msg_msg *msg)
  2409. { }
  2410.  
  2411. static inline int security_msg_queue_alloc(struct msg_queue *msq)
  2412. {
  2413.     return 0;
  2414. }
  2415.  
  2416. static inline void security_msg_queue_free(struct msg_queue *msq)
  2417. { }
  2418.  
  2419. static inline int security_msg_queue_associate(struct msg_queue *msq,
  2420.                            int msqflg)
  2421. {
  2422.     return 0;
  2423. }
  2424.  
  2425. static inline int security_msg_queue_msgctl(struct msg_queue *msq, int cmd)
  2426. {
  2427.     return 0;
  2428. }
  2429.  
  2430. static inline int security_msg_queue_msgsnd(struct msg_queue *msq,
  2431.                         struct msg_msg *msg, int msqflg)
  2432. {
  2433.     return 0;
  2434. }
  2435.  
  2436. static inline int security_msg_queue_msgrcv(struct msg_queue *msq,
  2437.                         struct msg_msg *msg,
  2438.                         struct task_struct *target,
  2439.                         long type, int mode)
  2440. {
  2441.     return 0;
  2442. }
  2443.  
  2444. static inline int security_shm_alloc(struct shmid_kernel *shp)
  2445. {
  2446.     return 0;
  2447. }
  2448.  
  2449. static inline void security_shm_free(struct shmid_kernel *shp)
  2450. { }
  2451.  
  2452. static inline int security_shm_associate(struct shmid_kernel *shp,
  2453.                      int shmflg)
  2454. {
  2455.     return 0;
  2456. }
  2457.  
  2458. static inline int security_shm_shmctl(struct shmid_kernel *shp, int cmd)
  2459. {
  2460.     return 0;
  2461. }
  2462.  
  2463. static inline int security_shm_shmat(struct shmid_kernel *shp,
  2464.                      char __user *shmaddr, int shmflg)
  2465. {
  2466.     return 0;
  2467. }
  2468.  
  2469. static inline int security_sem_alloc(struct sem_array *sma)
  2470. {
  2471.     return 0;
  2472. }
  2473.  
  2474. static inline void security_sem_free(struct sem_array *sma)
  2475. { }
  2476.  
  2477. static inline int security_sem_associate(struct sem_array *sma, int semflg)
  2478. {
  2479.     return 0;
  2480. }
  2481.  
  2482. static inline int security_sem_semctl(struct sem_array *sma, int cmd)
  2483. {
  2484.     return 0;
  2485. }
  2486.  
  2487. static inline int security_sem_semop(struct sem_array *sma,
  2488.                      struct sembuf *sops, unsigned nsops,
  2489.                      int alter)
  2490. {
  2491.     return 0;
  2492. }
  2493.  
  2494. static inline void security_d_instantiate(struct dentry *dentry, struct inode *inode)
  2495. { }
  2496.  
  2497. static inline int security_getprocattr(struct task_struct *p, char *name, char **value)
  2498. {
  2499.     return -EINVAL;
  2500. }
  2501.  
  2502. static inline int security_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
  2503. {
  2504.     return -EINVAL;
  2505. }
  2506.  
  2507. static inline int security_netlink_send(struct sock *sk, struct sk_buff *skb)
  2508. {
  2509.     return cap_netlink_send(sk, skb);
  2510. }
  2511.  
  2512. static inline int security_netlink_recv(struct sk_buff *skb, int cap)
  2513. {
  2514.     return cap_netlink_recv(skb, cap);
  2515. }
  2516.  
  2517. static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
  2518. {
  2519.     return -EOPNOTSUPP;
  2520. }
  2521.  
  2522. static inline int security_secctx_to_secid(const char *secdata,
  2523.                        u32 seclen,
  2524.                        u32 *secid)
  2525. {
  2526.     return -EOPNOTSUPP;
  2527. }
  2528.  
  2529. static inline void security_release_secctx(char *secdata, u32 seclen)
  2530. {
  2531. }
  2532. #endif    /* CONFIG_SECURITY */
  2533.  
  2534. #ifdef CONFIG_SECURITY_NETWORK
  2535.  
  2536. int security_unix_stream_connect(struct socket *sock, struct socket *other,
  2537.                  struct sock *newsk);
  2538. int security_unix_may_send(struct socket *sock,  struct socket *other);
  2539. int security_socket_create(int family, int type, int protocol, int kern);
  2540. int security_socket_post_create(struct socket *sock, int family,
  2541.                 int type, int protocol, int kern);
  2542. int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen);
  2543. int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen);
  2544. int security_socket_listen(struct socket *sock, int backlog);
  2545. int security_socket_accept(struct socket *sock, struct socket *newsock);
  2546. void security_socket_post_accept(struct socket *sock, struct socket *newsock);
  2547. int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size);
  2548. int security_socket_recvmsg(struct socket *sock, struct msghdr *msg,
  2549.                 int size, int flags);
  2550. int security_socket_getsockname(struct socket *sock);
  2551. int security_socket_getpeername(struct socket *sock);
  2552. int security_socket_getsockopt(struct socket *sock, int level, int optname);
  2553. int security_socket_setsockopt(struct socket *sock, int level, int optname);
  2554. int security_socket_shutdown(struct socket *sock, int how);
  2555. int security_sock_rcv_skb(struct sock *sk, struct sk_buff *skb);
  2556. int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
  2557.                       int __user *optlen, unsigned len);
  2558. int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid);
  2559. int security_sk_alloc(struct sock *sk, int family, gfp_t priority);
  2560. void security_sk_free(struct sock *sk);
  2561. void security_sk_clone(const struct sock *sk, struct sock *newsk);
  2562. void security_sk_classify_flow(struct sock *sk, struct flowi *fl);
  2563. void security_req_classify_flow(const struct request_sock *req, struct flowi *fl);
  2564. void security_sock_graft(struct sock*sk, struct socket *parent);
  2565. int security_inet_conn_request(struct sock *sk,
  2566.             struct sk_buff *skb, struct request_sock *req);
  2567. void security_inet_csk_clone(struct sock *newsk,
  2568.             const struct request_sock *req);
  2569. void security_inet_conn_established(struct sock *sk,
  2570.             struct sk_buff *skb);
  2571.  
  2572. #else    /* CONFIG_SECURITY_NETWORK */
  2573. static inline int security_unix_stream_connect(struct socket *sock,
  2574.                            struct socket *other,
  2575.                            struct sock *newsk)
  2576. {
  2577.     return 0;
  2578. }
  2579.  
  2580. static inline int security_unix_may_send(struct socket *sock,
  2581.                      struct socket *other)
  2582. {
  2583.     return 0;
  2584. }
  2585.  
  2586. static inline int security_socket_create(int family, int type,
  2587.                      int protocol, int kern)
  2588. {
  2589.     return 0;
  2590. }
  2591.  
  2592. static inline int security_socket_post_create(struct socket *sock,
  2593.                           int family,
  2594.                           int type,
  2595.                           int protocol, int kern)
  2596. {
  2597.     return 0;
  2598. }
  2599.  
  2600. static inline int security_socket_bind(struct socket *sock,
  2601.                        struct sockaddr *address,
  2602.                        int addrlen)
  2603. {
  2604.     return 0;
  2605. }
  2606.  
  2607. static inline int security_socket_connect(struct socket *sock,
  2608.                       struct sockaddr *address,
  2609.                       int addrlen)
  2610. {
  2611.     return 0;
  2612. }
  2613.  
  2614. static inline int security_socket_listen(struct socket *sock, int backlog)
  2615. {
  2616.     return 0;
  2617. }
  2618.  
  2619. static inline int security_socket_accept(struct socket *sock,
  2620.                      struct socket *newsock)
  2621. {
  2622.     return 0;
  2623. }
  2624.  
  2625. static inline void security_socket_post_accept(struct socket *sock,
  2626.                            struct socket *newsock)
  2627. {
  2628. }
  2629.  
  2630. static inline int security_socket_sendmsg(struct socket *sock,
  2631.                       struct msghdr *msg, int size)
  2632. {
  2633.     return 0;
  2634. }
  2635.  
  2636. static inline int security_socket_recvmsg(struct socket *sock,
  2637.                       struct msghdr *msg, int size,
  2638.                       int flags)
  2639. {
  2640.     return 0;
  2641. }
  2642.  
  2643. static inline int security_socket_getsockname(struct socket *sock)
  2644. {
  2645.     return 0;
  2646. }
  2647.  
  2648. static inline int security_socket_getpeername(struct socket *sock)
  2649. {
  2650.     return 0;
  2651. }
  2652.  
  2653. static inline int security_socket_getsockopt(struct socket *sock,
  2654.                          int level, int optname)
  2655. {
  2656.     return 0;
  2657. }
  2658.  
  2659. static inline int security_socket_setsockopt(struct socket *sock,
  2660.                          int level, int optname)
  2661. {
  2662.     return 0;
  2663. }
  2664.  
  2665. static inline int security_socket_shutdown(struct socket *sock, int how)
  2666. {
  2667.     return 0;
  2668. }
  2669. static inline int security_sock_rcv_skb(struct sock *sk,
  2670.                     struct sk_buff *skb)
  2671. {
  2672.     return 0;
  2673. }
  2674.  
  2675. static inline int security_socket_getpeersec_stream(struct socket *sock, char __user *optval,
  2676.                             int __user *optlen, unsigned len)
  2677. {
  2678.     return -ENOPROTOOPT;
  2679. }
  2680.  
  2681. static inline int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
  2682. {
  2683.     return -ENOPROTOOPT;
  2684. }
  2685.  
  2686. static inline int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
  2687. {
  2688.     return 0;
  2689. }
  2690.  
  2691. static inline void security_sk_free(struct sock *sk)
  2692. {
  2693. }
  2694.  
  2695. static inline void security_sk_clone(const struct sock *sk, struct sock *newsk)
  2696. {
  2697. }
  2698.  
  2699. static inline void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
  2700. {
  2701. }
  2702.  
  2703. static inline void security_req_classify_flow(const struct request_sock *req, struct flowi *fl)
  2704. {
  2705. }
  2706.  
  2707. static inline void security_sock_graft(struct sock *sk, struct socket *parent)
  2708. {
  2709. }
  2710.  
  2711. static inline int security_inet_conn_request(struct sock *sk,
  2712.             struct sk_buff *skb, struct request_sock *req)
  2713. {
  2714.     return 0;
  2715. }
  2716.  
  2717. static inline void security_inet_csk_clone(struct sock *newsk,
  2718.             const struct request_sock *req)
  2719. {
  2720. }
  2721.  
  2722. static inline void security_inet_conn_established(struct sock *sk,
  2723.             struct sk_buff *skb)
  2724. {
  2725. }
  2726. #endif    /* CONFIG_SECURITY_NETWORK */
  2727.  
  2728. #ifdef CONFIG_SECURITY_NETWORK_XFRM
  2729.  
  2730. int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, struct xfrm_user_sec_ctx *sec_ctx);
  2731. int security_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, struct xfrm_sec_ctx **new_ctxp);
  2732. void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx);
  2733. int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx);
  2734. int security_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *sec_ctx);
  2735. int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
  2736.                       struct xfrm_sec_ctx *polsec, u32 secid);
  2737. int security_xfrm_state_delete(struct xfrm_state *x);
  2738. void security_xfrm_state_free(struct xfrm_state *x);
  2739. int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir);
  2740. int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
  2741.                        struct xfrm_policy *xp, struct flowi *fl);
  2742. int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid);
  2743. void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl);
  2744.  
  2745. #else    /* CONFIG_SECURITY_NETWORK_XFRM */
  2746.  
  2747. static inline int security_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, struct xfrm_user_sec_ctx *sec_ctx)
  2748. {
  2749.     return 0;
  2750. }
  2751.  
  2752. static inline int security_xfrm_policy_clone(struct xfrm_sec_ctx *old, struct xfrm_sec_ctx **new_ctxp)
  2753. {
  2754.     return 0;
  2755. }
  2756.  
  2757. static inline void security_xfrm_policy_free(struct xfrm_sec_ctx *ctx)
  2758. {
  2759. }
  2760.  
  2761. static inline int security_xfrm_policy_delete(struct xfrm_sec_ctx *ctx)
  2762. {
  2763.     return 0;
  2764. }
  2765.  
  2766. static inline int security_xfrm_state_alloc(struct xfrm_state *x,
  2767.                     struct xfrm_user_sec_ctx *sec_ctx)
  2768. {
  2769.     return 0;
  2770. }
  2771.  
  2772. static inline int security_xfrm_state_alloc_acquire(struct xfrm_state *x,
  2773.                     struct xfrm_sec_ctx *polsec, u32 secid)
  2774. {
  2775.     return 0;
  2776. }
  2777.  
  2778. static inline void security_xfrm_state_free(struct xfrm_state *x)
  2779. {
  2780. }
  2781.  
  2782. static inline int security_xfrm_state_delete(struct xfrm_state *x)
  2783. {
  2784.     return 0;
  2785. }
  2786.  
  2787. static inline int security_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir)
  2788. {
  2789.     return 0;
  2790. }
  2791.  
  2792. static inline int security_xfrm_state_pol_flow_match(struct xfrm_state *x,
  2793.             struct xfrm_policy *xp, struct flowi *fl)
  2794. {
  2795.     return 1;
  2796. }
  2797.  
  2798. static inline int security_xfrm_decode_session(struct sk_buff *skb, u32 *secid)
  2799. {
  2800.     return 0;
  2801. }
  2802.  
  2803. static inline void security_skb_classify_flow(struct sk_buff *skb, struct flowi *fl)
  2804. {
  2805. }
  2806.  
  2807. #endif    /* CONFIG_SECURITY_NETWORK_XFRM */
  2808.  
  2809. #ifdef CONFIG_KEYS
  2810. #ifdef CONFIG_SECURITY
  2811.  
  2812. int security_key_alloc(struct key *key, struct task_struct *tsk, unsigned long flags);
  2813. void security_key_free(struct key *key);
  2814. int security_key_permission(key_ref_t key_ref,
  2815.                 struct task_struct *context, key_perm_t perm);
  2816. int security_key_getsecurity(struct key *key, char **_buffer);
  2817.  
  2818. #else
  2819.  
  2820. static inline int security_key_alloc(struct key *key,
  2821.                      struct task_struct *tsk,
  2822.                      unsigned long flags)
  2823. {
  2824.     return 0;
  2825. }
  2826.  
  2827. static inline void security_key_free(struct key *key)
  2828. {
  2829. }
  2830.  
  2831. static inline int security_key_permission(key_ref_t key_ref,
  2832.                       struct task_struct *context,
  2833.                       key_perm_t perm)
  2834. {
  2835.     return 0;
  2836. }
  2837.  
  2838. static inline int security_key_getsecurity(struct key *key, char **_buffer)
  2839. {
  2840.     *_buffer = NULL;
  2841.     return 0;
  2842. }
  2843.  
  2844. #endif
  2845. #endif /* CONFIG_KEYS */
  2846.  
  2847. #ifdef CONFIG_AUDIT
  2848. #ifdef CONFIG_SECURITY
  2849. int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule);
  2850. int security_audit_rule_known(struct audit_krule *krule);
  2851. int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule,
  2852.                   struct audit_context *actx);
  2853. void security_audit_rule_free(void *lsmrule);
  2854.  
  2855. #else
  2856.  
  2857. static inline int security_audit_rule_init(u32 field, u32 op, char *rulestr,
  2858.                        void **lsmrule)
  2859. {
  2860.     return 0;
  2861. }
  2862.  
  2863. static inline int security_audit_rule_known(struct audit_krule *krule)
  2864. {
  2865.     return 0;
  2866. }
  2867.  
  2868. static inline int security_audit_rule_match(u32 secid, u32 field, u32 op,
  2869.                    void *lsmrule, struct audit_context *actx)
  2870. {
  2871.     return 0;
  2872. }
  2873.  
  2874. static inline void security_audit_rule_free(void *lsmrule)
  2875. { }
  2876.  
  2877. #endif /* CONFIG_SECURITY */
  2878. #endif /* CONFIG_AUDIT */
  2879.  
  2880. #ifdef CONFIG_SECURITYFS
  2881.  
  2882. extern struct dentry *securityfs_create_file(const char *name, mode_t mode,
  2883.                          struct dentry *parent, void *data,
  2884.                          const struct file_operations *fops);
  2885. extern struct dentry *securityfs_create_dir(const char *name, struct dentry *parent);
  2886. extern void securityfs_remove(struct dentry *dentry);
  2887.  
  2888. #else /* CONFIG_SECURITYFS */
  2889.  
  2890. static inline struct dentry *securityfs_create_dir(const char *name,
  2891.                            struct dentry *parent)
  2892. {
  2893.     return ERR_PTR(-ENODEV);
  2894. }
  2895.  
  2896. static inline struct dentry *securityfs_create_file(const char *name,
  2897.                             mode_t mode,
  2898.                             struct dentry *parent,
  2899.                             void *data,
  2900.                             const struct file_operations *fops)
  2901. {
  2902.     return ERR_PTR(-ENODEV);
  2903. }
  2904.  
  2905. static inline void securityfs_remove(struct dentry *dentry)
  2906. {}
  2907.  
  2908. #endif
  2909.  
  2910. #endif /* ! __LINUX_SECURITY_H */
  2911.  
  2912.